Funds get blocked for a few blocks while sending/getting a transaction.
What is the purpose of it and how does it work?
I think the main purpose is to just prevent you from trying to spend a tx output that gets re-orged out of existence. At any point a block, or the last several blocks, or a lot of blocks can get orphaned, and the transactions included in them will be invalidated. However, the probability of a block getting orphaned decreases exponentially as more blocks are built on top of it (see the frequency of orphaned blocks here). So, it is really just a judgment call by the client software that after 'x' number of blocks there is an extremely low probability that the block containing that tx will get orphaned. In Monero the coins are "locked" for ten blocks, or what is now about 20 minutes, while in Bitcoin the core client software recommends waiting six blocks, or about 60 minutes (although the Bitcoin software refers to these coins as unconfirmed, not locked).
As jwinterm said, this is to avoid outputs being reused shortly after being created, in case of reorganizations.
It is important to realize that the effects of an output being invalidated are more severe in Monero than Bitcoin. In Bitcoin, if an input is invalidated, any transaction using it as an input is also invalidated. In Monero, the same applies, but the difference is that this output can be used by any blockchain user in Monero, as a partner in ring signatures, so an output can potentially be reused early with more probability than in Bitcoin.