Essentially, even without K, you can match against refl, but at least one of the endpoints must be an "unconstrained" variable. Both of these type check in Agda-sans-K:
foo : ∀ { A B : Set } -> A ≡ B → A → B
foo refl a = a
fooℕ : ∀ { A : Set } -> A ≡ ℕ → A → A
fooℕ refl a = a + 3
These cases are (probably) handled by a few standard induction principles for equality (AKA dependent elimination principles), such as "path induction" and "based path induction", which do not rely on axiom K, but are a fundamental ingredient in the definition of the equality type.
Instead, the following does not type check, since the two endpoints are constrained to be the same.
bar : ∀ { A : Set } -> A ≡ A → A → A
bar refl a = a
I'm unsure about why this does not work as expected. By comparison, in Coq this works fine:
Definition bar: forall A : Type, A = A -> A -> A :=
fun A p x =>
match p with
| eq_refl => x
end .
As the translation of the OP's code:
Definition foo: (bool = bool) -> nat :=
fun p =>
match p with
| eq_refl => 0
end .
In these two last cases, we do not even need dependent elimination, the regular non-dependent one suffices.
I guess that Agda, when no endpoint is "free", internally translates the match into some form which relies on axiom K, even if in some cases (like the above) there is no real need to do so.
One can indeed define the original why pattern match, by generalizing it so that at least one endpoint is "free".
why-generalized : {A : Set} -> (e : Bool ≡ A) -> ℕ
why-generalized {.Bool} refl = zero
why : (Bool ≡ Bool) -> ℕ
why = why-generalized
(Well, in this case we could also use why x = zero, but the point of the above code is to pattern match against refl)