There are several reasons for that. Linux is a unix-like OS, and Mac OS is based on the BSD kernel (they’re both Unix cousins). The core of both operating systems operates much differently than Windows in that they are set up to be more security-centric by default. Also, in Linux there is no such thing as a self-extracting or self-executing file (which is how a virus operates).
Linux requires permissions to be set to access system files, a normal user and any programs they launch can’t gain access to those files without specifically authorizing it via commands and passwords. This prevents any such virus from accessing the system.
Also, there simply aren’t any known virus “in the wild” for either operating system because those scumbags who write and spread virus know it would be pointless as it couldn’t do any real damage.
Windows can be made to be pretty secure by setting up user accounts and permissions correctly. They started going that way with Vista, but there are still numerous security holes a virus can exploit.
While it can take weeks or even months for Microsoft’s relatively small team to identify and create a patch for a security hole, there are literally millions of eyes examining Linux code and when a hole is identified a patch is released in a matter of hours. That is the real strength of open source software. I’ve written a few patches and bug fixes myself over the years.
Bottom line is that most virus are written to target Windows, and if there is a vulnerability that can be exploited someone will write code to exploit it. Most Linux users became such as a direct result of the sloppy coding done by Microsoft. Well, that and Linux is free and we’re cheap