Siri is always listening if you have it set to where you can say “hey Siri”.
I am unsure if they collect and record our conversations. I guess you just never know, but I can tell you your phone didn’t do what it did because it was listening to you.
In the first example, if you’re in wife and of someone in your contacts list tries to connect to that WiFi, your automatically asks if you want to share the password.
In the second example, if your browse the internet and were searching for CPR classes online, then your phone tracks all that and shows you those advertisements. This can be easily turned off in your phone’s settings.