"No temptation has overtaken you that is not common to man. God is faithful, and he will not let you be tempted beyond your ability, but with the temptation he will also provide the way of escape, that you may be able to endure it." (1 Corinthians 10:13 ESV)
Why would our Father in Heaven, who knows all things, allow us to be tempted? God allows us to be put into situations where our faith can be tested and strengthened. When we ask God to keep us from temptation, we acknowledge that we need His help to resist temptation.
When you are in a time of temptation or testing, know that God is with you to strengthen and show you how to overcome it with His help. Just ask Him.
“When Christians find themselves exposed to temptation they should pray to God to uphold them, and when they are tempted they should not be discouraged. It is not a sin to be tempted; the sin is to fall into temptation.” - Dwight L. Moody