Why did God create man with the ability to sin? I've read a highly favored answer here on C.SE that when people get to heaven they are no longer capable of sinning yet they still have free will. 

So my question is simple, why did he ever create us with capability to sin and then punish us if we do sin? Free will is out of the question now since it was clear that we can have free will without the capability of sinning.
When you say: “when people get to heaven they are no longer capable of sinning” not all Christians would agree with this response.  There is no evidence that any “free will” creature who has been reborn and experienced the wholeness of God’s love, would then rebel against that love.  Can’t and won’t are two different things. 


  Romans 4:16 Therefore it is of faith, that it might be by grace; to the end the promise might be sure to all the seed…


So a faith relationship enables a loving relationship.  God created man for a loving relationship, thus man was created with choice.  Faith is a choice, whom will I trust, will I trust the serpent or will I trust the Word of God?  

So your question: “why did he ever created us with capability of sin and then punish us if we do sin”?  God desires a loving relationship with mankind and the wholeness of love with some is evidently of more value to God than the rejection and damnation of others. 


  2 Peter 3:9 The Lord is not slack concerning his promise, as some men count slackness; but is longsuffering to us-ward, not willing that any should perish, but that all should come to repentance


God does not want any to perish!