Comparing C=O bond length in CO2 and CH2O
Drawing the Lewis structure for CO$_2$ and CH$_2$O shows that the C atom in CO$_2$ is sp hybridized and therefore forms a double bond (which is composed of a $\sigma$ and $\pi$ bond) with either O by overlapping one of its sp orbital with one of the sp$^2$ orbitals of O (since O is sp$^2$ hybridized) to form the $\sigma$ bond and one of its p orbitals with the p orbital of O to form the $\pi$ bond. 

In CH$_2$O, the C atom is sp$^2$ hybridized, meaning the C$=$O bond is formed by an overlapping sp$^2$ orbital from C and an sp$^2$ orbital from O (since O is sp$^2$ hybridized) for the $\sigma$ bond and an overlapping p orbital from C and a p orbital from O for the $\pi$ bond. 

So, the difference in the C$=$O bonds in the two compounds is in the constituent orbitals of their respective $\sigma$ bonds. The $\sigma$ bond of the C$=$O bond is shorter in CO$_2$ because it involves the overlap of an sp orbital with an sp$^2$ orbital. An sp orbital has more "s character" than an sp$^2$ orbital (you can think of an sp orbital as 50% s character, 50% p character and an sp$^2$ orbital as 33% s character, 67% p character), therefore the electron density in an sp orbital is on average closer to the nucleus of the C atom than in an sp$^2$ orbital, leading to a shorter $\sigma$ bond length. Because the $\pi$ bonds are formed from identical (up to orientation) p orbitals in each compound, the shorter $\sigma$ bond in CO$_2$ gives it a shorter C$=$O bond length than CH$_2$O.