In this case, reaction is redox (reduction and oxidation) type. As we know that glucose is reducing sugar, it has free carbonyl group which is oxidized to carboxyl group and in turn DNS is reduced to ANS (3-amino-5-nitrosalicylic acid) which is brown color compound which absorbs light mostly at 540 nm.
Thats why we use wavelength of 540 nm (for more understanding please read Beer's Law.)
In other way, glucose is reducing sugar (reducing agent) which reduces DNS into ANS and itself (glucose) is oxidized. ANS is detected with the help of spectrophotometer. More the sugar-----more color formation---more the absorption.