# Did I or Mathematica make a mistake?

Here is the code, it doesn't make sense. Or did I make a mistake?

ψ[n_, z_] := Sqrt[2/d] Sin[(n π z)/d + (n π)/2];
Simplify[Integrate[ψ[m, z] D[ψ[n, z], {z, 2}], {z, -(d/2), d/2}], Element[{m, n}, Integers]]
Integrate[ψ[m, z] D[ψ[n, z], {z, 2}] /. {m -> 1, n -> 1}, {z, -(d/2), d/2}]
(* 0 *)
(*-(π^2/d^2) *)


There is no mistake. In the first result you did not use the most general solution. But it is possible to make the results consistent. The trick is to use the assumptions and the option GenerateConditions already in the integration. Furthermore, for m equal n the denominator is zero, therefore one needs to take a limit m->n and only then set n to 1.

h=Integrate[ψ[m,z] D[ψ[n,z],{z,2}],{z,-d/2,d/2},
GenerateConditions->True,
Assumptions->n∈Integers&&m∈Integers&&d∈Reals]
Limit[h,m->n]/.n->1

Out[1]= (2 n^2 π (n Cos[n π] Sin[m π]-m Cos[m π] Sin[n π]))/(d^2 (-m^2+n^2))
Out[2]= -(π^2/d^2)


$$h_{m,n}=\frac{2 n^2 \pi (n \cos n \pi \sin m \pi -m \cos m \pi \sin n \pi )}{d^2 (n^2-m^2)},$$

$$h_{1,1}=-\frac{\pi ^2}{d^2}.$$