Is it safe for micro to switch pins from input to output in a loop?
What you describe is the standard way of scanning a matrix keypad. Essentially you are using the outputs as open-collector / open-drain (because you switch between output+low and input). For chips that do not have this possibility a diode can be put in series.

Switching a pin between input and output is totally safe and valid, it is done all the time, when a standard (push-pull type) pin is used to implement protocols like I2C and dallas/maxim 1-wire that need an open-collector output.

Depending on the value of your pull-up resistors you might need to wait a little between switching to a new output and reading the inputs. A few ms would be a starting point. 

To suppress key bouncing it might be advisable to have the readings of a key no less than 50 ms apart. This can be used to derive your timing plan.

You seemed to be a little worried about doing things as fast as a few ms apart. For a microcontroler running at a few MHz that is thousands of instructions apart!