So, behind your anus, there is your rectum, it’s a chamber that is usually empty, only if the colon is too full or shortly before you defecate does it get filled with stool.
Normal farts are gas coming from your colon and filling your rectum like a balloon, when you fart all that pressure is released and because the rectum is usually empty, only gas escapes.
But when you do have stool in your rectum… for example because your colon is overflowing into it or because the consistency of your stool is too fluid to be held back from the rectum, then that depressurization will push out with it the other content of your ass, straight into your underpants.
This is btw. how anal-sex is usually cleaner than people imagine it to be, because the rectum is (usually) empty and (mostly) clean.
Still… wash your hands/dick/toy before touching anyone, anything or anywhere else. Generally be hygienic guys.
Yes, the need to defecate is (mostly) governed by the rectal walls stretching.