"Rebuilding" a team means taking a group of veteran, but (mostly) mediocre players, and trading them for younger, unproven players, in the hope that the younger players will collectively "grow" into something better than what you started out with.
A losing team is one that is "stuck" with mediocre players. Often, they are veterans, but some of them might have qualities that are useful to, or fill a need, on some better team. Or you might have an inadequate team with (a few) "stars and scrubs" (think Mike Trout and the rest of the Angels), in which case you have good players to trade.
The better team is often "contending," and therefore wants veterans now. It is willing to give up future players to "win now." The worse team (by definition) can't win "now," and hopes that by trading present players for future players, they can win "later."
Also, the teams with the worst records get the earliest picks in the "drafts." These early draft picks help teams rebuild with the most promising "rookies."
An example of a rebuilding team in 2016-17 is the Chicago White Sox. Because the rest of the team was weak, they traded away stars like Chris Sale, Adam Eaton, and Jose Quintana, respectively, to "win now" teams like the Boston Red Sox, the Washington Nationals, and Chicago Cubs. The prospects they got in those trades upgraded a formerly mediocre farm system to arguably the best in baseball that could help them win in the future after they arrive in the Major Leagues. As a result, Bleacher Report projects them as the Number 5 team in 2020, even though they have few veterans left, unlike the higher-ranked Dodgers, Red Sox or Yankees.