In the shortest answer to a difficult question, yes, foreigners can buy homes in Thailand; it happens all the time. Unfortunately, there are some legal hurdles and laws on the books that make it seem hard to do.
Thai law provides that only a Thai national can own land with freehold title in Thailand. This leaves the foreigner with three possibilities then when trying to purchase land or a home.
The first method that foreigners have usually pursued has its benefits and drawbacks and involves putting the title of the property in the name of a trusted Thai individual. In most cases this is with a Thai spouse, naturally a trusted person in most cases. A Thai national who is married to a foreigner and has even changed her name to that of a foreigner is still eligible to own land by birthright. It is also possible that the trusted person be a business partner or friend, though this often feels too risky for many to have their home in the legal hands of another slightly more removed.
In order for a foreigner to have a home and land in their name they may open a company that does business in Thailand with a minimum 2 million baht investment. At that point a house maybe purchased in the name of the Thai company, with the total of land not to exceed one rai in most cases.
A third option not as often talked about is that of getting a legally binding document that shows the foreigner as the lender of the capital that a Thai uses to purchase the land with. This essentially makes the foreigner a co-owning partner in the house, though the title is possessed by the Thai. As there is still money outstanding owed to the foreigner, the Thai can never make any large decisions about the property without the consent of the foreign partner.
In all of these three cases for owning land, it is best to seek good legal counsel. Make sure you find a lawyer you are comfortable with, and who will draw up all legal documents in both English and Thai to be signed by both parties. There should be no mysteries for anyone involved. In most cases, a good lawyer can have things worked out for purchase of land or a house in a matter of days to weeks. It can actually prove much simpler than it seems.
Financing for foreigners buying property in Thailand
In most cases it is very difficult for foreigners to secure financing in Thailand. As with the above scenarios, it can be done through a Thai spouse sometimes, or through a Thai registered business. Those are the best options. Otherwise it is best to seek loan funding from overseas where the foreigner comes from, or even pay for the house in full according to terms of purchase. As the cost of nice Thai homes is comparatively cheap compared with the West, this is not difficult for many.
Leasing and subletting of foreign owned property
There are no laws against this in Thailand. In fact, many foreigners rent out acquired investment properties, or homes which they only occupy for a portion of the year.