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:
My brothers, consider it a great joy when trials of many kinds come upon you, for you well know that the testing of your faith produces perseverance (NJB)
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:
None of the trials which have come upon you is more than a human being can stand. You can trust that God will not let you be put to the test beyond your strength, but with any trial will also provide a way out by enabling you to put up with 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:13, 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.