The idea of annulment aka declaration of nullity is that the marriage is void ab initio. It's not dissolved, it has never existed (Catechism 1629).
Now, normally, this is caused by innocent things: for instance, if I pretend to be a priest and marry you and your sweetheart, the marriage can (and will) be annulled due to CCC 1630, which requires a priest for marriage at least between Catholics. Equally, if you happen to be too young for marriage. Or, actually, if you've got antecedent & perpetual impotence (Code of Canon Law Canon 1084§1).
Some situations are dodgier. Annulment per lig aka per causa ligamentes means you've tried to marry while already being married. That might be an oopsie!, in which case there is nothing wrong with it, you just need to clear your previous marriage. Or it might be intentional deceit, which does attract the need to confess and do penance.
Finally, there are the really nasty forms that cause nullity. Crimen is everyone's favourite one, which consists of you and your sweetheart conspiring to whack your current spouse so you can marry (actually, this is so whether you have had sex or not!). Quite obviously, there will be some penance involved in that case! Also, jail time.
The bottom line:
- Some things you do to enter into an invalid marriage may be a sin,
but simply entering into a void marriage is not a sin in itself.
- If it's a sin otherwise, it will, obviously, attract penance.
- Knowledge is important, of course. Knowingly entering into a marriage you know
would be void, such as when you know you're impotent, is basically