Is it just a clever algorithm?
Every social media platform is governed by algorithms. Twitter is a good example of this with its trending topics; a live, fast-moving algorithm that displays the most popular topics based on a number of rules (how many people are talking about the topic, at what speed the topic arose, how many verified users are talking about it, if it’s a breaking news item, etc).
Facebook probably uses the most advanced algorithms in the game. The benefit Facebook has over other platforms is the plethora of your friends’ data. Facebook knows who your family is, who your partner is (and ex-partners), and who your closest friends are based on interactions. You and your close friends probably have a similar way of thinking, or are interested in similar topics, so Facebook will assume that anything your closest friends are talking about will be of interest to you. This also means whatever your friends are searching for, reading, liking, hiding, and following could also be of interest to you. This is how clever targeted advertising comes into play.
We also can’t ignore the fact that companies advertising on Facebook have a huge range of data available to them. They can target people living in certain locations of particular genders and ages, people who attend certain schools or workplaces, commuters, people with particular interests, and so much more. Combined, these two methods of data gathering is probably the outcome of the adverts you’re seeing. No hocus pocus.