Flaw with Cross Entropy Error in Neural Networks
Make sure you use softmax as your final layer.  This will ensure that the outputs sum to 1.  You need this for cross-entropy loss to be meaningful.

Note that the correct cross-entropy loss is

$$-\frac{1}{n} \sum_{i=0}^9 y_i \log \hat{y}_i,$$

where $i$ ranges over all of the classes.  You omitted the dependence on the classes.

Once you change the outputs to use softmax, the anomaly you saw can't happen.  The network can't cause all nodes to output 1, because softmax renormalizes the outputs so they sum to 1.  This then works cleanly with cross-entropy loss, which only makes sense if the outputs are guaranteed to sum to 1 (i.e., cross-entropy loss only makes sense if we have $\sum_i y_i = 1$ and $\sum_i \hat{y}_i = 1$).