I had a PhD interview for a position but I had to cancel it because I had an offer from another one. However, I didn't accept the offer and now I would like to be interviewed for the first position. How could I ask them for this?
First, and most important, if you don't approach them then you get no happy resolution.
Second, you are entitled to your own choices and priorities and no one should be offended by that.
Third, probably nothing you do will guarantee success, but you can try to put yourself back in the game, at least, just by indicating that you would welcome an interview and an offer.
I would simply say that my circumstances are now different, without going into detail or apologizing for my earlier decisions. They may assume that they weren't my (your) first choice and might ask about it. It is always good to be honest in answering questions, but you need not try to anticipate them and answer them preemptively.
We, maybe you also, don't know how highly you were ranked earlier or whether they still have an opening. In the best case they will welcome your continued interest.
My advice, then, is not to go into detail about why you are now interested but be prepared to give an honest answer if asked. I doubt they would be surprised by any candidate having other options in such a case, nor by the candidate wanting to explore them.
You were honest with them originally, I think, not stringing them along. Perhaps they can appreciate that. But there are no guarantees.
So, I agree with Captain Emacs, that you should prepare an adequate explanation, but I don't think you should express it unless asked.
You can always ask in a contrite manner, trying to find an explanation why you declined them in the first place and explaining why you are now agreeing to join them.
I would be wary of a student with such indecisiveness and possible flightyness, but if they have a substantial number of positions and your credentials are strong, you may be in luck.
I pick up on Buffy's comment, there might be also another viewpoint: if there were concrete circumstances or newly arisen facts that triggered your change in decision, it is strongly recommended to mention them. If there is a good reason for you to reconsidering your choice, it is important for the committee to see what your thought process was in changing your decision.