In your first example, the result of the calculation is dimensionless (length divided by length), so it does not require any unit. It's a scalar value.
In your second example, the input gets parsed as "1/(2km)" which is equal to "0.5 km⁻¹". If you wanted half a kilometer, you'd have to enter "1/2*km"