The release of a deposit from escrow can be a little dicey but let’s talk about it. Your question specifically asks whether it is legal for the seller to refuse to release your earnest money deposit.
Technically, when money is held in escrow the HOLDER of the escrow (Broker of the Listing firm, an attorney who is managing the escrow account or occasionally a title company) is who would release the money. They are prohibited from doing so until either:
There is a closing and the funds are distributed as part of the closing
There is a MUTUAL RELEASE signed by both the buyer and the seller agreeing to all conditions of the release, or
A court which has jurisdiction over this matter determines who is entitled to funds
Ordinarily, a purchase agreement would have outlined the terms and conditions under which you would be entitled to receive your deposit. Most often, if you are denied financing, you would be allowed to receive the deposit in full from the escrow company. However, in order to be sure that both parties are in agreement and that no one is going to sue anyone else about the release of the money, both buyer and seller would need to sign a MUTUAL RELEASE. Usually this is a one page document which basically says, things didn’t work out for whatever the specific reason happens to be and everyone agrees to go home and nobody’s going to sue anybody. The release also allows for negotiating how the earnest money will be split. It may be:
Returned to the buyer (for some reason beyond their control, like lack of funding)
Retained by the seller as liquidated damages (because you caused them some expense)
Shared in some manner (say 50% to buyer and 50% to seller)
I would recommend that you approach (or that your agent approach) the LISTING Broker to discuss the merits of your request to have the funds returned to you. Be prepared to demonstrate the failure to get funding by providing a letter from your lender which states as much. Remain civil and approach them in the spirit of goodwill. If you believe that it would be fair to do so, then compromise and offer to split the earnest money as I suggested above sometimes happens.
As a last resort, consider the possibility of filing a claim in small claims court where you would be allowed to present your evidence as to why you feel to receive the funds back. In that case, the judge would decide who gets the money.
If it is any comfort to you, neither you nor the seller can get it until there is either a MUTUAL RELEASE or a court disposition. Something’s gotta give!