What are the rules regarding airlines picking up passengers at stops in foreign countries?
The short answer to your first question is that an airline can pick up passengers at an intermediate stop as long as it's previously been agreed by all the countries involved (see below). One example is Singapore Airlines SQ12, which flies SIN-NRT-LAX; many passengers leave and board the aircraft in Tokyo.

More generally, these rules are known as the freedoms of the air but they aren't consistently or fully implemented everywhere and a lot depends on agreements between individual countries. Your first question is about the fifth freedom:


  the right to fly between two foreign countries on a flight originating
  or ending in one's own country


As Wikipedia describes, this isn't always straightforward:


  The negotiations for fifth freedom traffic rights can be lengthy
  because in practice the approval of at least three different nations
  is required


If an airline stops in an intermediate country to refuel or for other technical reasons but isn't allowed to board or deplane customers, that would be the second freedom:


  the right to refuel or carry out maintenance in a foreign country
  without embarking or disembarking passengers or cargo


There's an interesting discussion of fifth freedom flights from a passenger perspective here, and you may get better answers on this topic on travel.SE.