Community banks are expanding their mortgage operations after struggling to gain ground with commercial loans.