Official Protestant Christian theology says that all pain comes from the Devil, especially among the positive thinking preachers today, but that is false.
God created pain and uses it on all of his people. There are several examples in the Bible; perhaps the best is the story of Joseph. Preachers like to say that there was no other way to do it, so God had to cause so much suffering, but there were other ways. Here is how God could have accomplished the very same outcome, except for the pain:
Every year Jacob and his sons no doubt sold sheepskins and wool to the passing caravans, then Joseph says, “Why let them take out skins and wool to Egypt and sell it for twice the price when we do all the work of raising and shearing and killing and skinning? Give me 5 servants and I will take the fruit of our labor to Egypt myself and we will gain much more profit.”
So he would make a trip every year to Egypt where he got to know the merchants there. He runs into a few problems from time to time while there, but he is able to solve the issues and impress the Egyptians with his wisdom. He eventually is offered the beautiful daughter of regional govern for his wife, and gladly accepts, and moves to Egypt.
Because of his wisdom and being blessed in everything that he does, he eventually becomes governor of the region and becomes well-known to Pharaoh. He is also becoming well-known for his dream interpretation. A few years later the Pharaoh has his dreams and calls upon Joseph to interpret them. The king is so impressed he puts Joseph in charge of managing the economic affairs of the kingdom.
When the famine is severe some of the brothers come to Egypt to buy gain and Joseph offers them some fine land, so they accept and everyone moves to Egypt.
Jacob did not have to suffer the loss of his favorite son, Joseph did not have to suffer the fear and abuse of being sold into slavery and being in prison. But God chose to do it that way because pain is part of what makes us who we are, it helps to mold our character, etc. And perhaps as a lesson for us, that we should not expect a happy and great life, which is what is being preached in many churches today.