Sounds like he is constipated. Got tired of sitting on the toilet. Are you doing anything for the constipation?
Have you had him checked for pinworms? They tend to migrate to the outside of the colon to lay their eggs at night. They look like tiny, white threads. If you suspect that pinworms might be the issue, you should be able to purchase "over-the-counter" medication for this condition (although you might have to ask the pharmacist as it may be stored behind the counter). Hope this helps ...
How do you know he does this before he or 'we 'go to bed?