Introduce a dummy depot (adjacent only to the "border" cells in the first or last row or column) and send one unit of flow from the depot to each black squarebanned cell. Let nonnegative decision variable $x_{i,j}$$z_{i,j}$ represent the flow along the directed arc from node $i$ to node $j$, and let binary decision variable $y_k$ indicate whether node $k$ is part of the red routeloop. Let $B$ be the number of blackbanned cells. To prevent trapped blacktrapping banned cells, you need flow balance constraints along with big-M constraint $$x_{i,j} \le B(1 - y_j) \quad \text{for all $(i,j)$},$$$$z_{i,j} \le B(1 - y_j) \quad \text{for all $(i,j)$},$$ which enforces $x_{i,j} > 0 \implies y_j = 0$$z_{i,j} > 0 \implies y_j = 0$.
For your example instance, the optimal objective valuemaximum score turns out to be $33$.: