As others have pointed out, it's an advertising technique called retargeting. Here are some of the technical details of how exactly it is done(Facebook's implementation might differ somewhat from this, but overall concept is same)
/*
DSP - Demand side partner (Entity which works with someone who wants to show their ads)
SSP - Supply side partner (Entity which works with some who have potential space on web to show ads)
/
1. When you visited Amazon.com, one of the DSP associated with them drop a cookie on your system to uniquely identify you as a user. Let's call it cookiexyz.
2. When you end up on Facebook.com, their SSP also drops a cookie on you, let's call it cookieabc.
3. Now only thing remaining is to determine cookiexyz and cookieabc are same users.
4. To do that, SSP requests a bid from Amazon's DSP(among others). While doing that, it calls one of the DSP's url(bid tag) which sends cookiexyz in request headers and sends cookieabc in query params. This uniquely profiles the user which DSP stores in their system and next time user requests a bid again, they can serve them ads based on preferences based on cookiexyz. In other words, info that your looked at some shoes on Amazon.com
/ disclaimer: I work as a dev in one of the Advertising partner for Yahoo and Bing. */