LOL...never thought about it really.
Two ways, I suppose, firstly, I agree with sandy.....as a side effect of it's primary function, it acts on the muscles of the bowel, slowing them down.
Secondly, particularly if they make you pass more water e.g diuretics, then the faeces clearly become "dehydrated" harder and one becomes constipated.