We try to hide the parts of ourselves that we do not like or are afraid to be judged on from others. When you meet Jesus, the Light, everything automatically becomes exposed. Jesus tells us we must first acknowledge our brokenness and debt (poverty of spirit) in order to start a relationship with him.
This is what this mourning is about, to understand how our sins have grieved God. Psalm 51 shows that the response isn't to merely sacrifice to God, but to turn our hearts from our ways to him. If you're spiritually dead in sin, your heart will become hard/uncaring and you will not mourn. But those who mourn are spiritually alive and feel the pain that they have caused.
You can't be comforted without first mourning. Satan also wants to show us the poverty of our spirit, but his goal is to condemn us for our lack of righteousness. When God reveals who we truly are, and our sin, our comfort is that he is willing to take us just as we are - that he loves us despite our inequities. We have hope in God, because if he can love and accept us at our lowest/worst then what have we to fear? We will be free, will be able to worship God, and will be able to love others who are also poor in spirit.