We might as well assume that we draw a maximal collection of walls: if there's another wall we can draw that will still leave the maze connected, then we should draw that wall, and that can only increase the length of the maximal path.
In that case, the maze contains no cycles: the only kind of path that starts at a location $X$ and comes back to $X$ is a path that retraces every step it takes.
In particular, a path that starts at the center, visits every location, and returns to the center must make every possible move twice. If we go from location $X$ to an adjacent location $Y$, then we enter a fragment of the maze which we can only leave by returning from $Y$ back to $X$.
If the grid is $n \times n$, there are $n^2$ cells, so $n^2-1$ pairs of adjacent cells without a wall between them, and so we need $2n^2-2$ moves to do this. This number of moves is always possible: just double every edge, then take an Eulerian tour.
If a path starts at the center and visits every location, but does not return to the center, then we can follow it up by a path from the final location to the center, and the result must have length at least $2n^2-2$. So the original path must have length at least $2n^2-2-d$, where $d$ is the distance from the center to its final location.
Moreover, we can always find a path that starts at the center, visits every location in $2n^2-2-d$ steps, and ends at a cell $d$ steps away from the center. Just take a path of length $d$ from the center to that cell, and double every edge not on the path. Then the resulting graph has an Eulerian path from the center to that cell of length $2n^2-2-d$.
There is always a cell that's at least $n-1$ steps away from the center: one of the corners. (The distance can only increase when we add walls.) So to make the minimal path as long as possible, make sure every cell is reachable in $n-1$ steps from the center; then there will be no path shorter than $2n^2-n-1$.
There are many ways to do this; here's one which is easy to generalize.