Invalidating a contract
The reality is that there aren't many judges out there who will force this.They instead usually award some kind of monetary restitution from the seller to the buyer.
However, a valid contract must always have certain elements, or it could be voided by a court of law. Parties cannot execute a contract to do an illegal act.
That doesn't mean cash, as there will often be financing involved as well.
Earnest money does move with the agreement, while the down payment and financing come at closing.
The parties to a contract must all be legally competent to enter into an agreement.
This includes being of legal age and mentally competent at the time of entering the contract.