Because the Lord redeemed (set free) Israel from Egypt all the first born males were to be offered to the Lord as sacrifice (vs 15). Since the Lord killed all of the firswtborn of Egypt both man and beast it was only reasonable that all the firstborn of Israel would now belong to the Lord.
I find it interesting the comparison of the donkey to natural man and the provision that is made that the donkey is to be redeemed with the sacrifice of a lamb, and if he is not redeemed, then his neck is to be broken, and death is the result. Praise God that He sent His Son to be our Lamb, so that we would have life. Donkeys were an unclean animal and thus needed a clean lamb to be offered for it. Man in his natural state (thanks to Adam) is also an unclean being and needed a pure lamb to be sacrificed for him as well.
As we know the Lord Jesus Christ left heavens glory to die on the Cross of Calvary for our sins. He was and is the sacrificial lamb of God to pay for out redemption.