Consider the quadratic functional $J_T$ on the Hilbert space $H^1(0,T)$ $$J_T(u):=\int_0^T(\dot u+u)^2dt\ ,$$ and let $0<m< M$ be given. The complete picture for the minimization problem of $J_T$ on $\{u\in H^1(0,T)\ :\ m\le u\le M\}$, as $T$ varies, is as follows:
For $0\le T \le T_0:=\log(M/m)$ the minimum value is $0$, and it is attained by exponentials $ce^{-t}$, with $me^T\le c\le M$ Geometrically, the zero set of $J_T$ is a line meeting the convex constraint set in a segment, that becomes a single point for $T=T_0$.
For $T_0\le T\le T_1:=\text{arcosh}(M/n)$ there is a unique minimizer, which is a decreasing solution of the free Euler-Lagrange equation $\ddot u=u$ with $u(0)=M$ and $u(T)=m$, namely $$u_T(t):={m\over\sinh T}\sinh t+ {M\over\sinh T}\sinh (T-t)$$ corresponding to the minimum value $$J_T(u_T)=2{(me^T-M)^2\over e^{2T}-1}.$$ Note that for $T=T_1$ the minimizer is simply $$u_{T_1}(t)=m\cosh(T_1-t)$$
For $T\ge T_1$ the unique minimizer is just $u_{T_1}$ prolonged to be constant for $T_1\le t\le T$, namely $$u_{T}(t)=m\cosh(T_1-t)_+$$ which is a $C^1$ function since $\cosh(T_1-t)$ has a $0$ derivative at $t=T_1$. The corresponding minimum value for $J_T$ then grows affinely: $$J_T(u_T)=J_{T_1}(u_{T_1}) +m^2(T-T_1).$$
$$*$$
Details.
More generally for $0\le \alpha\le \beta\le T$ denote
$$J(u,[\alpha, \beta]):=\int_\alpha^ \beta(\dot u+u)^2dt=\|\dot u\|^2_{2,[\alpha,b]}+\| u\|^2_{2,[\alpha,b]} +u(b)^2-u(\alpha)^2\ .$$
The situation being clear for $T\le T_0$, we assume $T>T_0$, that is case C in Carlo Beenakker's answer. So in the following $Me^{-T}<m$, and $J_T(u)>0$ whenever $m\le u\le M$.
If $u\in H^1(0,T)$ satisfies $m\le u\le M$ in $[0,T]$, but $Me^{-t}\le u(t)$ does not hold for all $t$, then $$v(t):=\max( u(t), Me^{-t})$$ has $\dot v(t)+v(t)=0$ in the non empty open set $\{v\neq u\}$, and $\dot v(t)+v(t)= \dot u(t)+u(t)$ a.e. in $\{v= u\}$, so $J_T(v)<J_T(u)$. The same hold, analogously, for $v(t):=\min( u(t), me^{T-t})$.
Therefore, any minimizer of the constrained problem must also satisfy for all $0\le t\le T$ $$Me^{-t}\le u(t)\le me^{T-t}$$ and in particular $u(0)=M$ and $u(T)=m$.
Also, if $u\in H^1(0,T)$ verifies $m=u(T)\le u(t)\le u(0)=M$ and $u$ is not decreasing, by easy intermediate value arguments there are $0\le \alpha < \beta\le T$ such that $$u(\alpha)=u(\beta)=\min_{\alpha\le t\le \beta}u(t)<\max_{\alpha\le t\le \beta}u(t)\ .$$ Then, putting for $0\le t\le T$ $$ v(t):=\begin{cases} u(\alpha),& \text {if }\ \alpha\le t\le b\\ \\ u(t), &\text {otherwise.} \\ \end{cases} $$ defines an element $v\in H^1(0,T)$, with $m\le v\le M$ such that $$J_T(u)-J_T(v)=J(u,[\alpha,\beta])-J(v,[\alpha,\beta])>0\ ,$$ thanks to the stated identity for $J(u,[\alpha,\beta])$.
Therefore, any minimizer of the constrained problem must be decreasing on $[0,T]$.
Finally, if $u(T)=m\le u\le M=u(\beta)$ for some $0=\alpha<\beta\le T$, we can compare $u$ with $$ v(t):=\begin{cases} u(t+\beta),& \text {if} \; 0\le t\le T-\beta\\\\ m, &\text {if} \; T-\beta\le t\le T. \\ \end{cases} $$ Again $J_T(u)>J_T(v)$ follows from the above identity for $J(u,[\alpha,\beta])$, for $$J_T(u)-J_T(v)=J(u,[\alpha,\beta])-J(m,[\alpha,\beta])>0.$$
Hence any minimizer of the constrained problem is decreasing and verifies $u(0)=M>u(t) \ge u(T)=m$ for $0< t\le T$. In particular, it solves the Euler-Lagrange equation $\ddot u-u=0$ in the interval $(0,\tau)$ (any small perturbation with compact support in $(0,\tau)$ leaves $u$ within the constraints). This gives:
$$u(t):= \begin{cases} {m\over\sinh \tau}\sinh t+ {M\over\sinh \tau }\sinh (\tau-t),& \text {if} \; 0\le t\le-\tau\\ \\ m, &\text {if} \; \tau\le t\le T. \\ \end{cases}$$
for some $0\le \tau\le \min(T, T_1)$; the corresponding value of the functional is $$J_T(u)=2{(me^\tau-M)^2\over e^{2\tau}-1}+m^2(T-\tau).$$
To conclude, one has to minimize the above expression w.r.to the parameter $\tau\in [0,\min(T, T_1)]$, finding the minimizer. In fact, it turns out it is decreasing w.r.to $\tau$, so that the minimum corresponds to $\tau=\min(T, T_1),$ ending the computation. : one has:
$${dJ_T(u_\tau)\over d\tau}=-{ \left( {me^{2\tau}-2Me^\tau + m \over e^{2\tau}-1 }\right)^2}\ . $$
(Note that this proves independently the existence of the minimizer, so we could have used piecewise $C^1$ functions instead of $H^1$, where however existence is also clear by convexity and weak compactness.)