1. He must have been late for the school.

2. He muse have been late for school.

---------------------------
Which one is grammatical? Do we have to put 'the' before 'school'?

#2 is correct, except for the typo.

I'd never use "the" in this case.
However, it is correct to say

He must have been late for the bus.
A bus is a specific vehicle, but "school" is a more vague entity, implying education and other activities, and not just the building.

Similarly, you can be

late for dinner
late for work
and so on.

Both sentences are grammatically correct, but there is a difference in meaning.

1. "He must have been late for the school."
In this sentence, the use of "the" before "school" suggests that there is a specific school in context, and he must have been late for that particular school. For example, if the conversation or text is already discussing a specific school, this sentence would fit better.

2. "He must have been late for school."
In this sentence, the absence of "the" before "school" implies a more general or generic reference to school in general. It means he must have been late for any school he attends or for school in general. This sentence is more commonly used in everyday speech or writing.

Therefore, whether to use "the" before "school" depends on the specific context and the intended meaning you want to convey.