Big thanks to Rob for pointing the way to that video!
This was straight-up crossover, pure and simple. Ted (or "Buck", as he hoped people would call him) was in Hawaii, where he served as a Jonathan Richman-like troubadour commentator on the attempts by Jules to convince her son Travis to come back to Florida. Either Ted was in Hawaii because he was on vacation, or because he ran away after losing his love. (Gooch ran off with Hooch; as Laurie told him, "You didn't stand a chance".)
Either way, eventually Ted was going back to wherever Sacred Heart Hospital was. (Somewhere near the Seaworld in California.) Ted is just too tightly wound up and buttoned down to toss aside his life with (nearly) complete abandon.
A 'Cougar Town' episode set outside their usual environs was the only way Lawrence could do a crossover with 'Scrubs'. If one of the 'Scrubs' characters showed up in West Gulfhaven, the audience would think Sacred Heart Hospital was located nearby. (And there is a Seaworld in Florida.) And a 'Cougar Town' resident wandering the corridors of Sacred Heart would achieve the same effect.
By the way, the options for which 'Cougar Town' character could appear in any revival of 'Scrubs' would have to exclude at least Jules, Ellie, and Jules' dad, Chick, as they all played important roles in that previous series. Too many questions as to why people at Sacred Heart wouldn't notice the resemblances.
So there is no splainin needed for the appearance of Ted, for there was no Zonk. Ted "Buck" Buckland was just enjoying some fun in the sun... and bringing it down to a sad, subterranean level.