Microsoft offers free Windows virtual machine images for development. Does Apple have something similar for macOS?
No, Apple only gives access to macOS beta for developers that are parts of the Apple Developer Program (more info about the latest macOS version here and release note of the latest beta as sep. 18 2022).
includes everything you need to develop, test, and distribute apps across all Apple platforms.
Apple publishes all the current beta full installers and there are apps and scripts (including the
softwareupdate command line tool that ships with macOS) for anyone to freely download these images for development and testing purposes.
You do need to acquire a license either from the free (or paid) developer programs or one of the free (or institutional) seeding programs.
Many virtualization systems work from these installers without requiring modification of the Apple installers which are code signed for anti-tampering and security purposes. The Apple “equivalent” of Microsoft’s first party hyper-V virtualization framework has many videos from WWDC and is officially documented online.
You can use this docker image to run mac in a VM. It also allows you to install xcode and use the iphone emulator, it's not very fast though.
If you need something a bit more performant and/or approved by apple look for services like macincloud or similars, it's definitely cheaper than buying a MacBook 🙂
There is a nice utility on linux for this called quickemu: https://github.com/quickemu-project/quickemu
It does require some knowledge of running linux but if you have a spare computer, you could install something like Ubuntu and use this utility to spin up a VM.