Let's consider the four color case.
If the square's dimension is $15$, then it contains $15^2 = 225 = 4\cdot 56+1$ cells and at least $57$ of these must be of the same color, say red.
Of these $57$ red squares, at most $15$ can be the uppermost (resp. lowermost; rightmost; leftmost) red squares in their columns (resp. columns; rows; rows), which gives at most $4\cdot 15 = 60$ red squares.
However, as mentioned in a comment, the uppermost (resp. uppermost; lowermost; lowermost) red square in the rightmost (resp. leftmost; rightmost; leftmost) column with a red square is both the uppermost (resp. uppermost; lowermost; lowermost) of its column and the rightmost (resp. leftmost; rightmost; leftmost) of its row, so its double counted. Therefore we have at most $60-4 = 56$ red squares satisfying any of the previous conditions.
It is clear that the square of dimension $15$ does not have the desired property. Surprisingly, the square of dimension $14$ does, as shown in the example below:

If this $X$-patterns is really optimal (I conjecture it is), the minimal grid size such that the property still holds for $n$ colors should be $4n-2$.