Clubs usually make sure to not have important players on a soon-to-expire-contract, and if they do, they rather sell that player than let the contract expire.
There are more complex cases where some players have multiple owners to their rights etc. Another more common case is that previous clubs usually have some sort of cut of future transfer fees as compensation for their "development" of the player.
Loans are basically "We got this young player John Talent contracted, but we can't give him enough first team experience atm due to competition in the team, so we'll loan him out to a club in a less competitive league where he'll gain it". So that club will pay some amount for that loan during a year.