My Quattroporte which I had up to 3 years ago had the option to change the exhaust sound to a loud growl simply by touching a button on the dash screen, my brother owns an M4 that changes the exhaust sound when in sport mode, which sounds like the crackle and splutter of an F1 engine. So yes it is legal, no it doesn’t fail the MOT as it isn’t part of the test.
Fitting an open exhaust was done back in the days of carburettors mechanically, but it was found the vehicle didn’t run very well because of a lean mixture as a result, no problem with EFI of course. That system didn’t last very long after tail pipes came along which changed the exhaust tone, something the go faster hot hatch back soon had fitted.