It should say in the paperwork that you usually sign for the used car dealership to hold your vehicle for you before you actually purchase the vehicle.
But most car dealerships can and will keep your deposit if you decide you don't want to buy the vehicle after they hold it for you.
And yes the car dealership can legally keep your deposit since they want to make sure you're serious about the purchase of the vehicle they're holding for you.
So don't expect to get your deposit back if you put a deposit up for the car dealership to hold the vehicle for you.