So to clarify, you had the fuel valve off, started the engine and then put the bike in gear? This will not hurt anything and will not cause the engine to die unless the carb is out of fuel. But then you could restart the engine so carb was not out of fuel, Sounds to me like engine died due to improper use of throttle or clutch when engaging a gear. Reading your other sympoms I suspect the battery is weak and Swifty has suggested a test.