God in His infinite wisdom and mercy knew that man could not live without another human because he was a “soul creature” and part of his nature was to be with someone. Matthew Henry once said, “man is a sociable creature. It is a pleasure to him to exchange knowledge and affection with those of his own kind, to inform and to be informed, to love and to be beloved.’” Also Solomon said in Eccl. 4:9, the “two are better that one, and woe to him that is alone.” (Matthew Henry commentary)
All of Eden would be nothing without a companion suitable for man, the paradise would become a desert. So God as it is said in Gen. 1:27-28, made male and female so that they could become companions and husband and wife and could multiple and fill the earth with men and women and boys and girls, generation after generation. Why did not God create male and male or female and female? Because He created, as the Bible says, male and female so that they might be fruitful and multiply the earth!
Verse 21 says God caused man to fall asleep and while he was sleeping He took a rib and closed the place and made woman from that rib.