'Serve' only applies to prison if used transitively, and the object is the prison sentence, e.g. "he served five years".
"He served for nothing" might apply to domestic or military service, or to tennis; the wording you are looking for is "He served time for nothing", which is unambiguously about prison.