No, it is not necessary to have residency to be able to buy property in Costa Rica. You can buy with your tourist status. Living here is another matter. As a foreigner and tourist you have to leave the country for 72 hours once every 3 months in order to renew your legal status in Costa Rica. Some of the foreigners without residency enjoy traveling and are visiting Nicaragua or Panama or discovering more of Central America in order to renew their visas.
There are many forms of residency available, we can help you to contact an attorney who can assist you in determining what residency status would work for you. If you plan on living here year round, you will find it easier if you have legal residency.