Does a pin (input pin Arduino) still float when connected to GPIO on RPI?
You need to enable the internal pull-up resistors which are designed to prevent undefined input states on unconnected inputs.

Change

pinMode(5, INPUT);


to 

pinMode(5, INPUT_PULLUP);


For more information on this see Arduino digital pins.