Let 4|n means n is divisible by 4. How to prove (4|n)→(2|n) in P?
Knowing that we have ¬(4|5), so we have ¬∀n(4|n). That is, we can not suppose 4|n because otherwise we would have ∀n(4|n) by generalization, but the hypothesis is in contradiction with ¬∀n(4|n). This shows that the hypothetical proof: if B ├ C then ├ B→C of propositional logic cannot be applied to predicate logic.
We prove (4|n)→(2|n) intuitively by suppose 4|n. If we cannot suppose it, how to prove it?
Sketch of a proof (Natural Deduction-like).
The proof obviously needs Peano axioms; thus, what we will prove is :
$\exists k \ (n = 4 \times k)$ --- assumed [a] (this is : $4 | n$)
$n = 4 \times k_1$ --- assumed [b] from 1) for $\exists$-elim
Now we need the associative law for $\times$, i.e. :
and we have, by transitivity of equality :
$n=2 \times (2 \times k_1)$
$\exists l \ (n = 2 \times l)$ --- from 5) by $\exists$-intro (this is : $2 | n$)
Note : you concern about Deduction Theorem is right for Hilbert-styple proof systems with "unrestricted" Generalization rule (see Mendelson's textbook).
The restriction on Universal generalization rule typical of Natural Deduction gives us the benefit of using $\to$-introduction rule (aka : Deduction Theorem) without restrictions also in predicate calculus.
In any case, the above proof is sound also for Mendelson's system, because the only use of Generalization in performed after the Deduction Th step to a variable $n$ that is not free in any assumption.