Origin and properties of the flat band in monolayer NbOCl$_2$