Why did God allow Satan to appear to Joseph Smith as an "angel of light," especially when Joseph was praying to Him for direction?

No one knows for sure why this happened, but we can take a pretty good guess at it. It is pretty well known that Joseph Smith practiced forms of divination. Divination is an occult practice that is an abomination unto God. Abomination means that God hates it. If Joesph Smith was using divination this could have been an hindrance to his relationship with God and Satan quickly took the opportunity to deceive him. We also know that when Joseph Smith was writing the book of Mormon he used divination. Since God has already warned us that he hates this practice we can be assured that the book of Mormon surely can not be trusted.

Important Point: No one can serve both God and Satan. If a person disobeys God by being involved in something that he had forbidden in his word that person will be deceived by Satan.