Here’s why: the macro expands to define a new type, and that is something you’re not allowed to do within a function:
julia> @macroexpand @ode_def begin
dx=a
end a
quote
mutable struct var"##402"{var"#43#F", var"#44#J", var"#45#T", var"#46#W", var"#47#Wt", var"#48#PJ", var"#49#TT1", var"#50#TT2"} <: (ParameterizedFunctions.DiffEqBase).AbstractParameterizedFunction{true}
...