Mortal sin occurs first in the mind, as soon as the will to do it is formed, meeting the three conditions. For example, adultery (sixth commandment) is preceded by thoughts of it - envy (ninth commandment), and vengeance, anger (fifth commandment) is preceded by envy (tenth commandment), and theft (eighth commandment) is preceded by envy (tenth commandment). In general the first and second commandments are sins against faith, hope, and charity – and these are formed in the mind first.
Baltimore Catechism No 4:
52 Q. What is actual sin?
A. Actual sin is any willful thought, word, deed, or omission contrary to the law of God.
Three ways we may sin, by “thought”–allowing our minds to dwell on sinful things; “word”–by cursing, telling lies, etc.; “deed”–by any kind of bad action. But to be sins, these thoughts, words and deeds must be willful; that is, we must fully know what we are doing, and be free in doing it. Then they must be “contrary to the law of God”; that is, violate some law He commands us to obey, whether it be a law He gave directly Himself, or through His Church. We can also violate God’s law by neglecting to observe it, and thus sin, provided the neglect be willful, and the thing neglected commanded by God or by His Church.
56 Q. How many things are necessary to make a sin mortal?
A. To make a sin mortal three things are necessary: a grievous matter, sufficient reflection, and full consent of the will.
“Grievous matter.” To steal is a sin. Now, if you steal only a pin the act of stealing in that case could not be a mortal sin, because the “matter,” namely, the stealing of an ordinary pin, is not grievous. But suppose it was a diamond pin of great value, then it would surely be “grievous matter.”
“Sufficient reflection,” that is, you must know what you are doing at the time you do it. For example, suppose while you stole the diamond pin you thought you were stealing a pin with a small piece of glass, of little value, you would not have sufficient reflection and would not commit a mortal sin till you found out that what you had stolen was a valuable diamond; if you continued to keep it after learning your mistake, you would surely commit a mortal sin.
“Full consent.” Suppose you were shooting at a target and accidentally killed a man: you would not have the sin of murder, because you did not will or wish to kill a man.
Therefore three things are necessary that your act may be a mortal sin:
(1) The act you do must be bad, and sufficiently important;
(2) You must reflect that you are doing it, and know that it is wrong;
(3) You must do it freely, deliberately, and willfully.