As with many situations, the answer is "it depends." No you are not legally required to have an attorney to represent you as buyer or a seller. But please do not stop reading yet. The decision to have or not have an attorney at closing can have serious impact.
Generally however most closings are conducted by an attorney who represents the lender and it is a requirement that an attorney be used to issue title to the lender, to assure the proper preparation of documents and to assure proper recording. Further generally a third person cannot prepare the transfer documents without an attorney.
So if there is an attorney closing the sale and purchase that represents the lender at closing, you do not absolutely need to have a separate attorney. They will explain the documents generally but they cannot give you legal advice or tell you that what the lender/other party is asking you to sign is excessive or beyond the typical language used. But is that really wise? Having your own attorney at closing can be important. When you negotiate your contract, do you have your real estate agent determine your contractual rights? Do you know how to review a title report? a survey? buyer's title insurance? what if there are last minute issues? what about your good faith estimate? your closing statement? Are there any contract issues?
For many people, the purchase of a home is one of their largest investments. You are signing documents that obligate you to borrow a great deal of money. Many have been the victims of fraudulent mortgage practices.
There are many good attorneys who can represent you for a reasonable fee in what may very well be one of the largest financial transactions of your life. Often they can do so while working within a limited budget if there is nothing atypical. As an attorney who performed closings in past years, who represented lenders, sellers and buyers, I can assure you there are many problems that can arise in a closing. I can also assure you that I have seen buyers and sellers make some decisions that I would have advised against had I represented them.
If you are buying the property at a foreclosure sale, unless you are very experienced in real estate, you should definitely have legal counsel to understand all the risks.