I was just thinking about how much space my garages occupies in my house. It's a lot of square footage for a car. Did people start building special rooms for their vehicles right away when vehicles where new (because vehicles might have been expensive and needed to be protected from the elements)? Or were vehicles moved into another room that was already being used for something else? I am guessing that most vehicle garages were built initially for rich people. Also I am assuming that the first vehicle garages were detached from homes.
Long before the automobile, people were storing vehicles in buildings.
On the farm, buggies, sleighs, carts and wagons could be stored in the barn. They might also be stored in a cart shed, which unlike the barn, was a building purpose built for storing vehicles.
People who were a little wealthier, or lived in town might build a carriage house. These could be built for one, or several, or (on a great country estate)a great many carriages. The fancier carriage houses might have living quarters on the upper floor for coachmen and grooms.
Keeping a carriage in a city was expensive. One was considered quite wealthy if you could afford to keep a carriage in town in London in the 18th century for example.
It was less expensive to keep a carriage in the country, as the horses could be usefully employed on the farm when not pulling the carriage, feed for the horses could be grown on the estate, and the land for the carriage house was less expensive.
The first garages for early automobiles either were carriage houses, or were modeled on carriage houses.
As you surmised, carriage houses were generally detached from the house (though often located conveniently close (especially if one did not have servants to hitch up the carriage and bring it around to the front door), and also located convenient to the road or drive).
Owners of the first private automobiles were generally wealthy, and likely already had a carriage house where they could store the car. As car ownership spread through the general populace, people would build garages where they had space. Builders soon realized that a garage was a feature which helped sell new houses, so, except in cities, where public transport was common and land was expensive, they tended to provide them.
Eventually, cars became more durable and resistant to the elements and eventually even people who could not build a garage might buy a car and park it on the street.