I switched from Android to Lineage OS, and I installed the most basic Gapps package possible, called 'pico', to get the bare minimum requirement for the Google Play store. I then manually disabled Google Play services. If I want to get to the Play store, I have to manually re-enable this.

Recently, I was in the car with my wife and son, and I mentioned that I miss the funny vines that were produced when vine.co was still active. Then, when I got home, I connected to wi-fi, went to Youtube.com through a mobile browser (I don't have the app installed), and the homepage was showing my 'funny vine compilations'. I was not searching for vines before this.

Then, today, I was telling my wife that we need a better vaccum cleaner, and that we should order a Dyson on Amazon. An hour later, I went to Amazon.com on my phone and the home page showed a deal on Dyson vaccum cleaners.

The reason I went through the trouble of putting a custom ROM on my phone was that I didn't want my phone listening to me. I'm not logged into my Youtube or Amazon accounts on my phone, and I didn't search for these things. I suppose it could be a coincidence, but I highly doubt it.

So my questions are: how is my phone spying on me? And how can I prevent this?

Hard to tell without knowing what apps you have installed. I wonder why you installed GApps at all (to access Playstore, you could also use Yalp or Aurora, and for other GServices there's always microG as replacement). A custom ROM doesn't necessarily protect you against "snooping apps".
– Izzy♦Jun 29 '18 at 11:40

Interesting, I've never experienced such behavior with stock (or manufacturer modified) Android. There must be something other than Android listening to you.
– SiXandSeven8thsJun 29 '18 at 19:51

Had this happen to me recently with LOS 15.1. Still investigating, but I currently suspect Google Framework Services' microphone permission, because I don't have other well-known culprits installed like the Facebook app. I've seen people say the Google services also listen in through the microphone, albeit the stories I found this in were from many years ago. (Won't put this in an Answer until I'm closer to being sure.)
– Don JoeNov 25 '18 at 23:24