Solution:
a. First of all we observe that a 2×2 square inside the grid can contain at most 3 cells belonging to the set S: indeed, if for contradiction there were a 2×2 square with all 4 cells belonging to the set S, then one could find a path, entirely contained inside the square, that contradicts the second condition given by the problem (for example, starting from the bottom-left cell of the square and going once right, once up, once left and once down one would return to the starting cell without ever crossing the same side twice).
Let us divide the whole grid into n2 squares, each of size 2×2. By what was said before, each of these 2×2 squares can contain at most 3 cells belonging to the set S and hence the set S can contain at most 3⋅n2 cells.
b. An example of a mazy set of 12 cells in a 4×4 grid is given by the set of shaded cells in the following figure:

c. We prove by induction on the number of cells that if a mazy set S has k cells, then there are 2k+2 sides adjacent to exactly one cell of S, that is
perimetro(S)=2k+2.
If k=1, then S=4=2⋅1+2, as we wanted.
Let us now assume that the statement holds for any mazy set with k−1 cells, with k≥2, and let us consider S a mazy set with k cells.
All the cells of S are adjacent to at least one other cell of S: indeed, given a cell x of S, there exists at least one other cell x′ of S distinct from x (S by hypothesis has at least two cells); by the first condition on mazy sets, it is possible to move from x to x′ moving only from cells of S to adjacent cells of S. In particular, there exists at least one cell adjacent to x.
There exists at least one cell of S adjacent to only one other cell of S: assume for contradiction that there are no cells of S with this property, that is, that all cells of S are adjacent to at least 2 other cells of S; let x0 and x1 be two cells adjacent to each other and let us construct recursively the sequence of cells x0,x1,x2,… in S, such that, for every i≥1, the cells xi and xi+1 are adjacent and xi+1 is distinct from xi−1 (since every cell of S is adjacent to at least two other cells of S, given xi−1 and xi, it is always possible to choose an xi+1 that satisfies the required conditions). Let t be the first time at which the sequence passes again over an already visited cell, that is, such that xs=xt for some s<t; this leads to a contradiction, since the sequence xs,…,xt contradicts the second hypothesis on mazy sets. Hence there must exist at least one cell of S that is adjacent to only one cell of S; let us call c such a cell.
It is now immediate to verify that the set S′ formed by all the cells of S minus the cell c, is still mazy. Since S is obtained from S′ by adding the cell c, the set of sides adjacent to exactly one cell of S is given by the set of sides adjacent to exactly one cell of S′, minus the side between c and S′, and adding the other three sides of c, whence
perimetro(S)=perimetro(S′)+2=(2(k−1)+2)+2=2k+2,
where the second equality holds by the inductive hypothesis.
Second solution:
We want to prove that the set S can be constructed recursively by attaching one cell at a time, in such a way that each attached cell is adjacent to exactly one of the previously attached cells; furthermore, we want to prove that every time a cell is attached, the perimeter increases by 2 with respect to the previous step.
Let x1 be an arbitrary cell of S and let S1 be the set formed by the cell x1, whose perimeter equals 4. If k=1, then we are done. If k>1, then the set S contains at least one other cell c. Thanks to the first condition of mazy sets, we know that it is possible to reach c starting from x0 and moving only through adjacent cells; in particular, there exists at least one cell x2 adjacent to x1; let us call S2 the set consisting of the cells x1 and x2 and observe that the perimeter of S2 is 6=4+2.
Suppose now that we have constructed the set Sj with the rules stated above and let us call x2,…,xj the cells that have been attached in order to obtain Sj; if j=k, then S=Sk and we are done. If j<k, then there exists at least one cell c′ in S that is not in Sj and, by the first condition of mazy sets, there exists a path of adjacent cells starting from x0 and arriving at c′; let xj+1 be the first cell traversed by this path that is not in Sj: in this way xj+1 is adjacent to the cell that precedes it in the path, which is indeed a cell of Sj. Now we want to prove that xj+1 is adjacent to a unique cell of Sj: suppose for contradiction that xr and xs are two cells of Sj adjacent to xj+1; then there exists at least one path completely contained in Sj going from xs to xr that crosses only adjacent cells (indeed, by construction of Sj, there exist two paths, Σ1 going from x1 to xr and Σ2 going from x1 to xs, that cross only adjacent cells; by traversing Σ1 backwards and then Σ2, one obtains the desired path). Let Σ be the minimal path from xr to xs (that is, crossing the smallest possible number of cells) that crosses only adjacent cells and that is completely contained in Sj; by minimality, this path can never cross the same side twice (otherwise the path could be shortened). Now, starting from xj+1, going to xr, traversing Σ until arriving at xs and finally returning to xj+1, one finds a path completely contained in S that crosses only adjacent cells and that never passes twice over the same side. We have thus found a contradiction to the second hypothesis of the problem and we have thus proved that xj+1 can be adjacent to at most one cell of Sj.
Let Sj+1 be the set obtained by adding to Sj the cell xj+1. Observe that the set of sides adjacent to only one cell of Sj+1 is given by the set of sides adjacent to only one cell of Sj, from which we remove the side between xj+1 and Sj and to which we add the other 3 sides of xj+1. From this it follows that every time we attach a cell, we add exactly 2 sides to the perimeter.
Since the perimeter of S1 is 4 and to this exactly k−1 cells are attached in order to obtain Sk=S, we have
perimetro(S)=4+2⋅(k−1)=2k+2.
d. Suppose that there exists a mazy set S of 300 cells in a 20×20 grid. The perimeter of the whole grid is 80, while by the previous point we know that the perimeter of S is 2⋅300+2=602.
Let T be the set formed by the 100 cells that do not belong to S; observe that the perimeter of T is at most 4⋅100=400 (that is, each cell of T contributes at most 4 sides to the perimeter), while the perimeter of the whole grid is 80.
Since by definition a side contributes to the perimeter of S only if it is adjacent to only one cell in S, we have that this side must either belong to the boundary of the grid, or be adjacent to a cell of T, whence
602=perimetro(S)≤perimetro(T)+ perimetro(Tabella) ≤400+80=480
which gives a contradiction.
Second solution:
Thanks to the previous point, we know that the set S has a perimeter of 602 cells; moreover, again from the proof of the previous point, we see that every time a cell is attached, exactly one side is used to attach the cell to the set. Hence the number of sides that are adjacent to two cells of S is exactly 300−1=299 (one side for each attached cell). Hence the existence of S requires at least 602+299=901 sides. Since the grid possesses in total 840 sides, the set S cannot exist.