The median aggregate should also take account for missing values, i.e. nulls. If the there are nulls in the array, the ORDER BY puts them last. Then the result is not correct. If there are more than 50% nulls, the median is also null.
Would you mind publishing a generic quantile aggregate function, e.g. quantile(numeric, float)?