For example, on the lemmy.ml frontpage sidebar, there's a rule 3, no porn. Is it instance-wide?
Rules placed on the front page of an instance are the instance-wide rules. So, no porn allowed on lemmy.ml.
Can I create my own community with nsfw comment?
Yes but on an instance that allows it. You'd have to make a separate user account there.
And if not, can I use a federation to post a nsfw content to an instance that allows nsfw from my account on lemmy.ml?
Yes. Unless the admins of an instance have reasons to block (not federate with) another instance, you can cross-post to any one that your instance federates with. It's even possible to an extent, to cross-post to other projects/networks. You'll have to follow the remote instance's guidelines, though.