When is it required for a game to receive a rating by an official or quasi-official rating board like the PEGI or the ESRB? I know that almost every game which is sold in a brick-and-mortar store almost anywhere in the world must have an age label. But what about games which are distributed globally as download or browser-based games? Is there a reason to get a content-rating for such a game? When yes, which rating board(s) need to rate it, considering that anyone in the world can play it and each country has its own local rating system with different criteria?
Game ratings are not enforced by any country for any kind of game. They'll just ban your game, if they found it objectionable enough. The rating is more of a de-facto standard used to make the end-user aware about the content of the game, so that kids do not play games containing extreme violence.
You'll be required to submit ratings only if you're making games for major consoles, such as PlayStation, XBox or Wii. Microsoft accepts ESRB and few other ratings for games in Windows Phone and Windows RT platform too, although it's optional.
Sony, Nintendo and Microsoft will fail your game unless you have a proper age rating, as this is a major compliance criteria for any game submission. The compliance is known as TCR for XBox, TRC for PlayStation and LotCheck for Nintendo Wii/DS/DSi.
There're few countries which requires explicit rating by one of the approved rating agency to be eligible for distribution. As found at WP game rating guidelines
South Korea requires game rating from one of their approved rating agency, while in
Taiwan you need to self declare the age rating yourself. If you don't put any rating while submitting your game, Microsoft will not distribute your game to these countries. Apple in this case asks developers to rate their own game and checks thoroughly if they put it correct as part of their submission process.
India on the other hand use their own Govt. agency CBFC to rate a game. However CBFC is primarily for movie ratings and they generally don't enforce any publisher to make a rating submission, although they can use their own discretion to ban a game. Also as mentioned by Andon M. Coleman in the comments below, Australia doesn't enforce you to make a rating submission, however that's only if your game doesn't have any adult content. If it does, then you'll have to submit it for rating analysis or else it'll be banned till you do.
In short the the ratings are enforced mostly by the distribution channel you're using, since they don't want to lose their credibility and would like to keep their customers happy. Govt. doesn't have anything in that(except for few countries such as Brazil, Russia and South Korea). So to answer your question, when does a game need an official age rating, it's when your distribution channel requires it and that's too dependent on the region where you want to distribute your game.
More info about the rating system being used in various countries can be studied from this wikipedia link.
PS: I've tried to put as much info as I could get for the countries which I got to know about. This answer might not be true for few other countries which actually requires the game to be rated. Feel free to let me know if you know something which I've not mentioned here.