When installing Linux / Ubuntu on top of this, where does the bootloader / grub get installed so that the MBR knows to execute this instead of just Windows?
When you install GRUB on BIOS systems, it completely replaces the original MBR bootcode with its own. Later, when you select "Windows" from the boot menu, it does mostly same thing the original MBR bootcode would have done.
Windows uses a traditional MBR which is very generic – all it does is look for the 'active' partition and execute its VBR sector. So GRUB doesn't actually need the original MBR at all – when you choose the "Windows" item in GRUB, it just directly loads the Windows partition's VBR.
(Meanwhile, the GRUB MBR is a complete opposite – it doesn't care about partitions and always loads the remainder of GRUB core from a reserved disk area.)
Note that most new computers do not use an MBR – they have UEFI firmware which stores all bootloaders as ordinary
*.efi files in the "EFI system partition". These are very similar to .exe files, and the firmware keeps its own boot menu (a list of .efi files to try).
So when you install GRUB on an UEFI system, it copies its files to the EFI system partition alongside Windows bootloader files, then inserts itself as the topmost entry in the EFI boot menu (with a higher priority than the old Windows entry).
Later, when you select "Windows" from the GRUB menu, it again doesn't do anything special – it just starts the same original Windows
Bootmgfw.efi file that's still on the EFI system partition.