Have him checked for genetic disorders like PSSM or EPM. Sometimes that is the first clinical sign. What breed is he? My friend had a horse that did that and it was due to him pulling a muscle in his hips.
Also some horses do it when they are starting to tie-up. Make sure he has good feed with plenty of minerals and vitamins.
I knew another horse that did this. It was his way of trying to get out of working. If he is lazier or doesn't enjoy working try to push him past it. Maybe try to change things up like riding him outside. You may need a crop and give him a gentle tap when he tries to "pee".