Every file is a box
with boxes inside.
The extension names the container: labelled blocks that say what's inside and where. An MP4 holds a video stream and an index; a DOCX is a ZIP of XML files. Pick one, or open your own, and see it laid out byte by byte.
"Allowed" is what the container's specification permits. "Plays here" asks this browser, live, whether it would play that exact combination. A file can be perfectly valid and still not play, because the box is supported but the codec inside isn't.
MP4 is the container (wrapper). H.264 is the video codec (compression method) inside the container. MP4 + H.264 is the most common combination.
No. Changing only the container (remuxing) without re-encoding the video data has zero quality loss.
Yes. MKV to MP4 conversion is usually just a container change - the video data is identical. No re-encoding needed.
YouTube accepts many containers but recommends MP4. Internally, YouTube uses its own streaming formats based on MP4 and WebM.
Both are video containers that can hold H.264 video. MKV supports more features (multiple audio tracks, subtitles). MP4 has better compatibility.