You could change the the equation can return a null string instead of a 0.

Or use

=median(if(a1:a5<>0, a1:a5))

... confirmed with Ctrl+Shift+Enter.