Provided the dealer has put wording similar to "conditional" or "subject to loan approval" in your contract, then yes, it is legal for a dealer to take back your car and cancel the contract within a certain period after buying.