Is installing Mavericks on Hackintosh legal?
It is not in accordance with Apple's license to run OS X on a non-Apple hardware as per Apple's license agreement for OS X Mavericks. Since this question is not about a preinstalled version of OS X (which is only on new Macs), the Mac App Store License section is applicable, along with the Other Use Restrictions section that is common for both kinds of installations. The license agreement states (emphasis mine):


  2. Permitted License Uses and Restrictions.
  B. Mac App Store License. If you obtained a license for the Apple Software from the Mac App Store, then subject to the terms and conditions of this License and as permitted by the Mac App Store Usage Rules set forth in the App Store Terms and Conditions (http://www.apple.com/legal/itunes/ww/) (“Usage Rules”), you are granted a limited, non-transferable, non-exclusive license:
  (i) to download, install, use and run for personal, non-commercial use, one (1) copy of the Apple Software directly on each Apple-branded computer running OS X Mountain Lion, OS X Lion or OS X Snow Leopard (“Mac Computer”) that you own or control;
  
  ...
  H. Other Use Restrictions. The grants set forth in this License do not permit you to, and you agree not to, install, use or run the Apple Software on any non-Apple-branded computer, or to enable others to do so.


See the SOFTWARE LICENSE AGREEMENT FOR OS X MAVERICKS PDF for more details. You can also get to this agreement by going to the Software License Agreements page, then navigating to Operating System Software Tools and Server, and choosing OS X (Mavericks).
As an additional point, even though OS X Mavericks is free for Apple Mac users, it's only because Apple has changed how it accrues revenue from Mac hardware sales by adopting the subscription model (which has been in use for iOS devices for longer), wherein Apple defers accruing a portion of the revenue from Mac sales for providing software updates in the future (including free apps and such). Apple has defined this deferral as two years for iOS devices and four years for Macs. This is the only way for Apple to adhere to accounting laws in the U.S. Searching for "apple subscription accounting" on the web would yield many results on this topic.


Whether using Apple's software in violation of Apple's license is illegal is a question with potentially different answers in different legal jurisdictions.