Good question. As it turns out, there isn't an official Catholic position. That is, the Catechism does not address the question of why temptation occurs. What follows is an argument combining the thinking of several different Catholic scholars.
First, the definition of temptation is
An attraction, either from outside oneself or from within, to act contrary to right reason and the commandments of God (Glossary to the Catechism)
To never be tempted would mean that God would have to both control your thoughts (making anything wrong repulsive to prevent internal temptation) and the actions of other people (to prevent external temptation). This would clearly interfere with free will. As Charles Pope says:
temptation is the “necessary” result of freedom. As free persons who are invited to love God and to say yes to his will, we must be permitted to say no. There must be real alternatives to what God offers. If God could force our yes, then we would not be free and our yes would have no real meaning.
Additionally, facing temptation is actually beneficial to the believer. As Father Fortea says:
Without temptation, there would be no opportunity for us to grow in virtue every time we successfully resist the allure of sin and remain faithful to God’s will... In other words, we could say that God permits a certain amount of darkness in this world (temptation and sin) so that a purer and brighter light (virtue and salvation) can be gained. So God allows temptation because He knows that much good can come from it if we resist.
On this point, see also James 1:2-3:
Consider it all joy, my brethren, when you encounter various trials, knowing that the testing of your faith produces endurance. (NASB)
God will, however, prevent us from facing temptations beyond our ability to resist. (If we truly could not resist, we would not be culpable for our actions.) See 1 Corinthians 10:13:
No temptation has overtaken you but such as is common to man; and God is faithful, who will not allow you to be tempted beyond what you are able, but with the temptation will provide the way of escape also, so that you will be able to endure it.
The Catholic Harbor of Faith and Morals takes this "moral shaping" idea a step further, writing:
God allows us to be tempted out of '''mercy''', for the good of our souls... He allows us to be tried by temptation to give us the opportunity of manifesting our loyalty to Him, and acquiring a claim to the recompense He promises us. Thus He has only our welfare in view. (my bold)
On this point, the Vulgate version of Tobit is cited:
And because thou wast acceptable to God, it was necessary that temptation should prove thee. (12:!3, Douay-Rheims)
Additional that site offers the following positive benefits of facing temptation:
- Rouses the believer from an otherwise apathetic state
- Cleanses imperfections (by making us aware of them)
- Humbles us
- Increase spiritual strength (you can't grow in faith by standing still)
- Make us more charitable in our dealing with others
Thus we see that the tempter does us good service, and his temptations are steps in the ladder which leads to heaven. Therefore let him who is tempted rather pray for strength to resist the temptation than for its entire removal.