It was (originally) for localization: ja.reddit.com would (for example) give you a Japanese interface. Eventually they realized what a horrible idea l10n is for a community-oriented site, and dropped the translations, but kept the `lang` that it would apply attributes. Eventually subreddit moderators figured out that you could use this to provide multiple variants of the per-subreddit CSS, such as dark modes, custom filters, and other silliness[0].
Testing it out I found something interesting. You can put in subreddit.reddit.com and it redirects to reddit.com/r/subreddit. But any 2 char prefix works sends to old.reddit.com (a.reddit.com -> reddit.com/r/a)
e.g. hackernews.reddit.com -> reddit.com/r/hackernews