It was Joshua who was told to destroy everyone in Jericho except Rahab and her family.
Joshua destroyed Jericho because he had firm believe in God's words and did not want to disobey God's orders. He also knew that God has a bigger plan for him and his people.
Rahab and her family was asked by God to be spared because she had a strong faith in God. Rehab also hid Joshua's spies in her attic and saved them from King's soldier.