During the pandemic, this issue was solved at one of my kid’s schools by simply having a “unwanted food” tray at the end of the line. If you can’t have milk or gluten because of an allergy, drop it off at the tray and someone else will take it. The tray was invariably mostly empty by the end of the lunch periods. And this was at a large middle-class public school.
The social aspect of all this is massive. When everyone had free lunch at school, the vast majority of kids took advantage of it - again, in a suburban, middle-class public school. My kids noticed a big reduction in lunch-related harrassment when everyone was getting the school lunch, not just the poor kids with the free lunch vouchers and the kids with single parents.