In the US, it's the norm. When I was in elementary (primary in the UK) school, it was split about half between packed sandwiches (with a box of OJ and a small bag of chips or similar snack) and queuing up at the school's lunch counter for a hot meal (usually cheap, not great quality, and heavily subsidized for those students that qualified). I'm not sure when it started, but my guess would be the 1930s, in an effort to ensure every child had at least one full meal a day. And at least in my current region, the school now offers breakfast before school begins (though this is almost exclusively used by students who qualify for free lunches - I don't know any middle-class families that rely on the school breakfast).
From what I know, the food quality and cost varies widely. Here (rural Minnesota, US) the elementary school lunch is about $2.50 (HS is about $3.75) for the kids who don't qualify for financial aid or free meals. Breakfast is also available at a similar cost.
I've never eaten it, but my kids generally enjoy the food and my wife, who's volunteered at the school often and eaten lunch there, says it's OK. They also offer an optional PM snack in elementary school at additional cost. Snack milk is free for everyone.
OTOH, I've heard of other school districts around the country where the food is total crap and only the poorest children who can't afford to have breakfast at home/bring a lunch will eat it.
Ours was hit or miss. The pizza was good, if you like a greasy thin slice (I do). Simple things like Mac & cheese were good too. The meatloaf was terrible. The hamburgers weren’t great - the patties were cheap meat (possibly with lots of filler) and the buns mediocre. My fav was the thanksgiving lunch - they did a pretty good turkey, stuffing, and gravy.
The real problem was vegetables - they were guaranteed to be over cooked and mushy.
I don't know the entire history but as a federal program it started in 1946. [1] It's long been sort of a political hot button. As you say, the impetus was (and is) that children from poor or otherwise disadvantaged home environments got at least one full meal at lunchtime.
I grew up in the US Midwest, and I'm pretty sure it was a norm throughout the region, if not the entire country. So far as I know every school had a hot lunch, and also a hot breakfast. As I understand it, the rationale was that there were in fact kids who came to school hungry, and that it interfered with their ability to learn. At the same time, the lunch was available to everybody, and payment was handled in a way so that the kids never knew who was getting it for free. The teacher would collect lunch money in the morning. I brought a nickel every day for milk.
(This is where the idea of the school bully demanding your lunch money came from. Today, lunch money is handled through some sort of payment system, and the kids don't have to handle their own lunch money or have it stolen from them).
Of course there is no such thing as a single purpose government program. The state bought the milk from farmers, effectively subsidizing it. And so forth.
I never understood the magic of why the meal had to be hot. Usually the food was vile, and I greatly preferred to bring a sandwich from home. I wondered why the cafeteria couldn't just make a nice sandwich for everybody. Perhaps there was a time when heating institutional food was the best way of making sure everything was sanitary.
Even to this day, I bring a sandwich or leftovers from home. My daughter just left for college, so her supper portion goes in my lunch bag for the next day. ;-) My employer has a cafeteria, but maybe only 1/4 of the employees use it. The rest bring bag lunches. The cafeteria and break rooms have microwaves for us to use.
This may be a regional thing. In the Midwest, eating prepared food every day will kill you.