Seeds of Life in Space (SOLIS): II. Formamide in protostellar shocks: Evidence for gas-phase formation