The problem is because for K[1] =1 sum is singular.We need to use a Limit.
t1 = 2;
indicator[x_] := Piecewise[{{1, 0 < x < 1/2}}, 0];
(*problème du controle*)
E1 = D[u[x, t], {x, 2}] - D[u[x, t], {t, 2}] ==
indicator[x]*(Cos[\[Pi] t] + Sin[\[Pi] t]) Sin[\[Pi] x];
(*données initiales propres k=1*)
ic = {u[x, 0] == Sin[\[Pi] x],
Derivative[0, 1][u][x, 0] == \[Pi] Sin[\[Pi] x]};
(*Condition aux bord de Dirichlet*)
bcc = {u[0, t] == 0, u[1, t] == 0};
(*résolution analytique de l'équation*)
sol2 = DSolve[{E1, ic, bcc}, u, {x, 0, 1}, {t, 0, 12}]
(* solution *)
((u /. sol2[[1]])[[2]][[1, 1, 1, 1]] /.
K[1] -> n)(* In here K[1] now it will be: n *)
(* Sqrt[2]*(Cos[Sqrt[n^2]*Pi*t]*Piecewise[{{1/Sqrt[2], n == 1}}, 0] + (Sqrt[2]*Cos[(n*Pi)/2]*(n*
(Cos[Pi*t] - Cos[n*Pi*t] + Sin[Pi*t]) - Sin[n*Pi*t]))/((-1 + n^2)^2*Pi^3) +
Piecewise[{{1/(Sqrt[2]*n), n == 1}}, 0]*Sin[Sqrt[n^2]*Pi*t])*Sin[n*Pi*x]*)
fff[n_] :=
Sqrt[2]*(Cos[Sqrt[n^2]*Pi*t]*
Piecewise[{{1/Sqrt[2], n == 1}},
0] + (Sqrt[2]*
Cos[(n*Pi)/2]*(n*(Cos[Pi*t] - Cos[n*Pi*t] + Sin[Pi*t]) -
Sin[n*Pi*t]))/((-1 + n^2)^2*Pi^3) +
Piecewise[{{1/(Sqrt[2]*n), n == 1}}, 0]*Sin[Sqrt[n^2]*Pi*t])*
Sin[n*Pi*x];
fff[1](*For n =1 is Singular !! *)(* Error messages*)
Limit[fff[n], n -> 1]
(*((\[Pi] t Cos[\[Pi] t] - (1 + \[Pi] t) Sin[\[Pi] t]) Sin[\[Pi] x])/(4 \
\[Pi]^2)*)
And now a solution:
M = 50;(*Infinity is now 50 ! *)
SOL[x_, t_] := ((\[Pi] t Cos[\[Pi] t] - (1 + \[Pi] t) Sin[\[Pi] t]) \
Sin[\[Pi] x])/(4 \[Pi]^2) + Sum[fff[n], {n, 2, M}];
Grid[Partition[
Table[Plot[SOL[x, t], {x, 0, 1}, Exclusions -> None,
PlotRange -> All, AxesLabel -> {"t", "x(t)"}], {t, 0, 12}], 3],
ItemSize -> 10]

Plot3D[SOL[x, t], {x, 0, 1}, {t, 0, 12}, AxesLabel -> Automatic]
