In some places it's perfectly legal to hike during the night although you must be very cautious because hiking during the nigh is more dangerous than hiking during the day.
I would recommend hiking during the day so you can see more easily and enjoy the hike more although hiking at night can be done with good flashlights or lanterns etc.
However some places make it illegal to hike their mountains at night for good reason because some people have gotten severely injured or have died and had to be rescued during the night.
So it can be dangerous to hike at night and sometimes illegal to hike at night in some places.
So check with the town or place you plan to hike to be sure it's legal to hike at night in the area or trail you plan to hike.