Configuration files are read top to bottom, so location blocks look like they are evaluated that way. They are not: nginx picks the longest matching prefix, then lets a regex override it, in a fixed order that has nothing to do with the order you wrote.
location = /health { } # 1. exact match wins immediately
location ^~ /assets/ { } # 2. prefix match, stops regex evaluation
location ~ .php$ { } # 3. regex, first match in file order
location / { } # 4. longest prefix, used if no regex matched
Exact matches are checked first and stop everything. Regular expressions are the only ones evaluated in file order, which is why moving two regex blocks changes behaviour and moving two prefix blocks does not. ^~ on a prefix means “if this matches, do not consider regexes at all” — the usual fix when a static asset location keeps losing to a .php$ block.