"Worst possibly imaginable thing" : Is this gramatically correct?

The noun “thing” needs a determiner:

1 "The worst possibly imaginable thing"- possibly is an adverb modifying “imaginable” – thus = "The worst {possibly imaginable} thing" = (i) The worst thing that a person might or might not be able to imagine. (ii) The worst thing, but one that we think might be unimaginable.

… and that is a strange idea. A “possibly imaginable” thing might be the graph of y = 1/(1-x): it is possible to imagine (= form a picture of in your mind of) this graph, but not everyone can imagine it.

2 “The worst possible imaginable thing"- This is the commoner form. "The {worst possible} imaginable thing"- {worst possible} is adjectival phrase and modifies “thing”. This is idiomatic. = (i) The worst possible thing that you can imagine, i.e. you cannot imagine anything worse.

my teacher kept repeating this over and over. … If yes, I seek an explanation as to why.

I could possibly imagine that it is a joke. A phrase that amuses him.