Why does my browser connect to unknown third party sites when I visit different webpages?

Many different reasons.

  1. Almost all ads you see come from 3rd parties.
  2. The developers of the site may use 3rd party libraries to acheive their goals, such as jQuery and others.
  3. The site may depend on data from another site, such as an API.

The list is giant, however these 3 are the main reasons. Most are harmless and nothing to worry about, however, one should always educate themselves of the dangers.

Edit: According to @smonff, you should worry about it

Oxymoron has given 3 common reasons, but in addition (or rather additional clarification) many if not most websites will call scripts from domains such as google-analytics. Some of these scripts attempt to gather information about individual users, while many are more interested in users' interactions with particular sites, or correlations across multiple sites.

Ghostery has already been mentioned as one way of avoiding some of these. You might also consider adblock plus (particularly useful if you are on a slow connection, or come across those ads that expand on mouseover).

Another powerful option is to install noscript. This will block all scripts from any source until you tell it to allow them. It's quite annoying at least at first, before you instruct it about sites you regularly visit. Even with most scripts allowed it still offers some protection against more esoteric threats (though that may be starting to veer off topic) but doesn't strip 3rd party images (for example) unless being called from a script.

These blocking tools aren't mutually exclusive - some combination may be helpful.