Is this due to cost, or infrastructure, or path dependency, or incentives?
I understand that batteries are more efficient (1) - but this does not take into account the quantity of rare materials required for batteries vs. hydrogen (2).
Why do most car manufacturers prefer electric batteries over hydrogen fuel cells?
Because it's cheaper today, easy to pack the batteries under the floor, won't decrease the range much and won't have as fast acceleration.
Apart from internal combustion engine cars burning hydrogen (which is very silly!), there is no pure hydrogen car today. All cars that are marketed as "hydrogen fuel cell" cars are actually fuel cell - battery hybrids.
Hydrogen has a very high energy to mass ratio. Unfortunately, it's energy to volume ratio is very poor. You need to store it under huge pressures. The tanks to do this cost much and still have a high size. While the hydrogen in those tanks won't weigh much, the tanks need to be able to withstand such high pressures that the tank weight will be high. Yep, the weight for equal range will be somewhat lower than in electric car batteries but not much. The volume, not so much a benefit for hydrogen as the heavy batteries can be stored in the floor of the car. With hydrogen tanks, you don't have as much freedoms for their placement.
Hydrogen fuel cells aren't durable enough today. The chance that the fuel cell stack in an average hydrogen fuel cell battery hybrid needs replacement during its lifetime is higher than the chance a battery in a purely electric car needs replacement during its lifetime.
The hydrogen fuel cell and the tanks to store hydrogen today cost so much that you actually save costs by simply increasing the battery size to the desired range rather than using a very small battery and doing the rest by using hydrogen.
Then there's the acceleration. If you increase the size of the batteries, you increase the acceleration of the car. That's what most car buyers affluent enough to buy new technology want. If you put a hydrogen fuel cell + storage system there, the acceleration increase won't be as big unless you make the hydrogen fuel cell stack ridiculously powerful and big (and expensive!).
Today the situation is thus that a purely electric battery-based car makes more sense than a hydrogen car. Some day the situation could very well be different. If that day arrives, then the hydrogen infrastructure needs to be built. Hydrogen storage requires very high pressures and still has a poor volumetric energy density. Thus building the infrastructure won't be cheap. The electric car charging infrastructure is trivial in comparison.
There's also far poorer energy efficiency of creating hydrogen by electrolysis and converting it to electricity in fuel cells, as compared to charging and discharging a battery. This also makes the situation more favorable to battery-based cars.
There are a number of issues with hydrogen as an energy source.
Firstly, there is a lack of infrastructure for hydrogen. The same can be said for battery charging, but slowly the number of battery charging stations is increasing. Nothing comparable has yet been done for hydrogen.
Sourcing hydrogen is another problem. The main ideas for sourcing hydrogen is to split the water molecule into hydrogen and oxygen using electrolysis. The two problems with that is countries with ocean coastlines have an advantage. The other is the energy required to split water molecules is significant and requires electricity. To provide the electricity required, large solar energy farms, supplemented by wind farms would be required. If electricity is being generated to split water molecules it is more efficient to direct that energy into battery storage. Also, if sea water is used, one of the waste products will be salt, that will need to be disposed of.
Storing hydrogen in tanks has its problems too. There is an issue with hydrogen leaking from its containment vessel. Because the hydrogen molecule (H2) is very small it has a tendency to maneuver past the atoms with the walls of its containment vessel and escape. This leads to the other issue with hydrogen, safety.
Hydrogen is not only highly flammable it is explosive! Ensuring leaking hydrogen does not contact naked flames or sparks or other sources if ignition is a major safety concern. Because of this hydrogen fuel tanks need to be strengthened to prevent the tanks from leaking or rupturing during collisions.
In the U.S. there are tax credits only for battery-powered electric-vehicles.
Wealthy people don't really mind heavy vehicles or expensive vehicles.
Truck buyers like the torque of battery-powered electric-vehicles and then don't mind the weight of the batteries. (Fuel-cell electric-vehicles actually have less performance than battery-powered electric-vehicles but then the average car-buyer gets more acceleration than they can really handle with battery-powered electric vehicles. Well, when the battery-powered electric-vehicle attempts to reach the same range as fuel-cell electric-vehicles then battery-powered electric-vehicle weight goes through the roof but so does vehicle performance.)
There are not very many hydrogen fueling stations in the U.S. outside of California. Blame that situation on the federal government as well. Well, the federal government could build hydrogen fueling stations or federal legislation could require that the powergrid buy electricity from hydrogen fueling stations such that the hydrogen fueling stations would then have two business models. (Now the city of Hempstead NY has a hydrogen fueling station at Point Lookout.)
Now long-haul trucks, city buses, and trains are likely to go to hydrogen-fuel-cells because they can use centralized fueling and because they are already very heavy but need range.