Google Adsense provides publishers the option to show ads relevant on a user's browsing history (via tracking cookies) as well as contextual ads. Since Google's goal is to make both the publisher and the advertiser more money, Google will choose to show whatever it has found to be more profitable.
On top of that, if Google does not have ad fill, such as in the case of articles about dinosaurs, it will sometimes advertise its own products (which the publisher will still get paid for) instead of showing a blank spot (as some advertising companies will do.
tl;dr Google shows ads based on a visitors browsing history if it thinks it will make you more money that way.