In short
It is part of the design on the bike but if a bike has been damaged the stability of the handlebars gets worse.
Personal experience
In many years of riding (Dutch) bikes I have noticed a distinct different in how they handle when you only guide the handlebars rather than holding them.
When looking at the bikes I could not see enough of a difference so I started looking online (when that came available.)
My first 'own' bike was a folder, bought with the best intentions, I never learned to ride it with no hands, even taking one hand from the bars to indicate was not easy and I never loved to ride it. It was only when I got my next bike that I learned it was not me, it was the bike.
I own a folding bike again and again it is not wanting to go straight without holding the handlebars, almost no rake and trail.
The bike I loved most turned to out to have a lot of trail. I had to let go of that bike because of other damage and lack of space at the time.
Trail and Fork Rake
The position of the axle of the wheel compared to the line through the ball head is called trail, and the more trail, the more forward the bike wants to go. One often used way to make the trail bigger is by bending the design of the fork. The difference between straight and bend is called rake.
The design on the ball head and the angle of the fork at the crown also have influence.
Full picture and attribution here. Author: Rishiyur1, Public Domain.
Handlebar width
A well designed bike will have handlebars that go with the steering characteristics as well as with the general looks that belong to that kind of bike.
In themselves handlebars do little when riding without hands, but as soon as you hold the bars they have a lot of influence.
Wide bars have more of an influence than narrow bars, the point you hold your handlebars will also change how much power you get out of your bars. Drops or straights in itself should not make much of a difference but your position on the bike will differ because of that as well as where you hold your drops.
Weight on the front of the bike
When I ride the same bike, same riding position but with a basket empty or with up to 10 kilos (22 pound) of groceries, I do see a difference in how well the bike goes straight. This is a bike I can not ride without hands, at all, but I need much less hold on the handlebars when the basket is well laden.
I have also noticed that same on other bikes, more weight on the front makes it want to go forward.
Which makes it harder if you want to ride without hands on a bike designed to be riden with part of your weight, via your hands, on the handle bars.
Riding without hands on a bike
I can not do it, but many people can adjust their balance on almost any bike and keep it going straight without touching the handlebars.
It is a combination of balance, adjustments as soon as the bike veers off, and confidence that you can pull it off.
But remember the old saw:
Mum, look, riding without feet (on the pedals,)
Mum, look, riding without hands (on the bars,)
Mum, look, riding without teeth (in the mouth.)
Bike damaged
Any bike that is right will stay up when you hold it by the saddle and push it walking besides it, balancing it from that position. But some bikes do take a lot more balancing or can not be kept straight at all, because their wheels are out of line or other parts are damaged.
If your bike feels like it steers different or does not want to go straight after a fall or an accident, check (and/or have it checked by a mechanic who knows what he does) and look for the line of the wheels as one of the things.
Riding with no hands at all
There are a few bikes designed for riding with no use of hands, and a few trikes for people without hands, and those I am aware off are all recumbent bikes and trikes that steer mostly by balance.
My current rides are a Flevo bike and a Flevo Trike, which are rather different from the average bike. I still need by hands on the bars when riding, even though others do not.
Further reading and watching
Rake and trail on a blog post by Dave Molton.
Rake or no rake on a fork on bike forums.
Bicycle physics about steering, assumes a certain education level.
Video which explains how bikes stay up.
Video in which you can see a Flevobike in action.
Video in which a rider explains the advantages of a Flevobike.