Well... the menu bar being at the top of the screen really dates back to the much older co-operative multitasking roots of System 5 or 6, when the screen completely switched from application to application, and you had to pop a floppy disk in each time you switched from "system" to your application using switcher and multifinder. Multitasking is much newer than the foundations of the macintosh UI. There used to be a little icon in the top right hand corner in System 7 and 8 called the application menu, which you used to tell which application you were in, and to navigate to a different application. That's been replaced by the dock in OSX, but the menu bar used to function as the application switcher as well.
It is possible for menus to be put into the title bar of the window, but that is the prerogative of the developer. Logic Pro, for example, has some menus in the menu bar, and some – those contextual to each window – in the window's title bar. Application commands are not necessarily contextual to a window. In MacOS, the viewport is considered to be the limits of the application's effects, rather than the window edges.
I think the top menu bar was retained in MacOS because of a few reasons:
#1: backwards compatibility with existing applications · the title bar is customised in many apps, but the menus are assumed to always live in the menu bar. In OSX, they kept it familiar for the trad users, and it's a good way to tell which application or window has focus. Logically, you only have one application running, rather than a separate application for each document, so the menu bar is never duplicated unnecessarily. In the Finder, for example, with lots of windows open it would be very annoying to have lots of menu bars everywhere.
#2: since the menus spawn themselves downwards, and windows can be smaller than the menu bar, or positioned on the screen in ways that would cause the menus to overflow, the menu bar is most ideally placed at the top of the screen. English reads top to bottom, right to left, the menu bar follows that structure.
#3: the mouse can easily be relocated to the top of the screen by trying to drive it off the edge, just throw the mouse in that direction and it'll end up on the edge. It's convenient to have important UI features positioned on the edge of the screen, such as the dock. If you start using a tablet or pen interface, where the screen edges aren't the strongest UI area as with a mouse, but instead the weakest, the dock and the menu bar become much harder to access. In aircraft systems, touch screens tend to have buttons down the edges to replace this easy-access screen edges feature.