This question is essentially asking the difference between capacity to commit a crime and competence to stand trial. There is a link to each below.
The capacity of a person to commit a crime has to do with their mental state at the time that the alleged crime was committed. They must be able to understand what they are doing -- the nature and possible consequences of their action. By contrast, competence to stand trial has to do with the person's ability to comprehend the charges against them and participate in their own defense at the trial.
For example, a person may be percectly competent to stand trial but may plead not guilty by reason of diminished capacity to a first degree murder charge. They may say they were drunk when they committed the crime and could not have formed the intent necessary to be guilty of first degree murder. Now that they are no longer drunk, they are competent to stand trial. In this case, the difference between competence and capacity would be a crucial one.