ETA: I thought this would be the first response, so I made it rather complete. Everybody ahead of me has dealt with some of the story.
You (OP) are mixing up two utterly separate systems.
Your phone has continuous internet connectivity over (simplifying here) the mobile phone system. This is automatic and seamless and just works pretty much wherever you go. This is the data that you pay $X for Y gigabytes per month.
As a completely separate and unrelated matter there’s wifi.
The wifi universe was designed for things like houses or hotels or businesses. Where a premises owner would put up a “hotspot” that reached out a hundred feet or so and authorized people could connect to it instead of needing to lug around a network wire & plug into a wall socket at your house or at the Starbucks or wherever.
What happened next is that some businesses realized that offering free wifi was a way to attract customers. Some businesses let anyone connect. Others require you to get a password from the clerk / cashier.
Next some companies realized they could make money by installing wifi in, say, every Starbucks and selling subscriptions for $10 a month allowing use in every Starbucks nationwide. And giving Starbucks HQ a cut of the money. To connect to those you need an account and a password.
Then the cable TV/Internet companies got in on the act and many places that are wired for internet via their cable company are also broadcasting wifi signals that anyone who’s a subscriber to that cable company can connect to. I have Comcast at home and so I can connect to wifi spots all over the country coming out of people’s houses and businesses.
But all wifi is ultimately local. The phone needs to actively do stuff to connect to any given hotspot. If that one fades away the phone has to do a whole rigamarole to connect to another. It was never designed for connecting moving things.
Pretty much all wifi services offer unlimited (or nearly so) data. Though they may limit speed.
So pretty quickly phones gained the ability to connect to wifi as well as connect to the traditional mobile system. There’s a setting in the phone menu to turn wifi on or off. People who use lots of data like to use wifi as much as possible since they’re not paying for it. Instead they’re piggybacking off somebody else’s. With their implicit or explicit permission.
If your phone’s wifi is turned on, as you walk around a retail environment or downtown your phone will be “hearing” dozens of signals from dozens of shops and businesses. And promiscuously trying to connect to each of them, regardless of whether the wifi owner wants outsiders on its network or not.
That’s what your phone is doing. And often failing to connect for lack of a password. So it bugs you for one, or announces that it tried and failed to connect to network “abc123”.
So that’s what’s happening. What to do about it?
Me, I leave wifi off unless I’m at home or in specific familiar locations. I’m happy to save my metered mobile data when I’m at home by using my own unlimited wifi, but I don’t want my phone sticking its wifi connector into any old network it hears out in public. Who knows what’s behind it? I think of snagging random public wifi signals about like I do of picking up food off the sidewalk. Yes, it’s free food. But at what risk?