Why would God create beings with the capacity to sin? Life on earth is filled with the horrible effects of sin.  Why did God create mankind with the capacity to sin?  Was there a higher purpose in this or was there a specific reason for it?

I'm specifically looking for an answer based on biblical teaching as interpreted in the Protestant tradition.
The reason God created anything at all is for His glory.  (Isaiah 43:1-7 (esp v.7), Rev. 4:11, Col 1:15-16)This is a hard concept to grasp for anyone, even for a committed Christians.  So the answer is that sin is there to glorify God.  You may ask, "How does sin glorify God?"  Sin glorifies God's attributes of justice and wrath, not His most popular attributes.  Many Christians view God a pure love, and that is correct; but God is also pure wrath "a consuming fire" and pure justice. (Hebrews 12:29, Deuteronomy 32:4)

Think about it this way.  If you had a family member who had been murdered by a criminal and you were present at the trial and the Judge decided to acquit the criminal despite eye witness testimony, how would you feel?  Would the judge be 'glorified' in your eyes.  God is glorified in the judging of sinners.  In the case of true Christians, Christ stands as their sacrifice.  So if we go back to the courtroom example we see the Judge's Son offering to take the punishment of the criminal and the Judge offering to take the criminal into his family to reform him.  

So God is glorified by sin in two ways.  He is glorified by judging sin righteously and also by His Son taking the punishment for some of the sinners.

Romans 3:22-26 (NKJV):


  For there is no difference; for all have sinned and fall short of the glory of God, being justified freely by His grace through the redemption that is in Christ Jesus, whom God set forth as a propitiation by His blood, through faith, to demonstrate His righteousness, because in His forbearance God had passed over the sins that were previously committed, to demonstrate at the present time His righteousness, that He might be just and the justifier of the one who has faith in Jesus.