因为have a good time后面省略了一个介词in,介词后面接的是名词或动名词,to do 的话就是表示要做什么事。
have a good time (in) doin sth. 介词in 省略了。