The phrase comes from classical funerary writing.
呜呼 is a sigh,
哀哉 literally ‘how sad!’. Together they are the conventional sign-off of formal eulogies (
祭文) since the Han dynasty. It already appears in
《诗经》:
於乎哀哉. Modern speakers borrow it half-jokingly to mean ‘and that was the end of that.’