As others have noted, it was most common in cases where one inheritance was male-only and one wasn't, so as to prevent the lands from splitting.
A good example would be the Anne of Brittany, who was duchess of Brittany in her own right. She was married first to Charles VIII of France, and had no living issue. On his death, she was then almost immediately married to Louis XII of France (the next king of France and a cousin of Charles VIII) to keep Brittany in French hands. They only had daughters (who couldn't inherit the French crown, but could inherit Brittany), so Louis XII had their eldest daughter (Claude of France) marry his cousin and heir presumptive (the future Francois I).
It could also be used to settle inheritance disputes (Henry VII and Elizabeth of York have already been mentioned; Henry VII claimed the throne by right of conquest, but also due to Lancastrian descent, and made a major propaganda push to emphasize their marriage as uniting the two houses and ending the Wars of the Roses). To take another example, Charles of Bourbon (constable of France and later leader of the Imperial troops in the 1527 sack of Rome) married his second cousin, Suzanne of Bourbon to settle the inheritance of the duchy of Bourbon (she was the senior descendant, he was the senior descendant in the male line); after her death, Louise of Savoy (another cousin, the Queen Mother of France, and 14 years his senior) proposed another marriage for the same reasons; when he refused she had his estates confiscated, leading him to betray France and ally with the Holy Roman Empire instead in an effort to get his lands back.