If all sticks are in a flat plane, they all must be either
| (nothing else!).
Now, to build a closed path, the sticks must return to where they came from. Let's call this the origin point $(0,0)$. Furthermore, we can think of
— as the X-axis and
| as the Y-axis.
Turns out, each
— changes our X-axis by $1$ and
| changes our Y-axis by $1$! Since we need both our coordinates to be at $0$, the number of
|s each have to be even.
When we are given access to the third dimension...
We get WAY more options. Instead of choosing left or right when rotating 90 degrees, we can also choose to go up, down, 45-degree up, 88-degree up, and everything in-between. Wow!
What's the shortest solution, then?
Probably 7 sticks! Here's a visualization in GeoGebra.
Why's that the shortest solution?
Well... With 2 sticks, the best we can do is form a 90-degree angle with distance $\sqrt2$ from the origin. So, 3 sticks isn't enough.
Also, I previously did this for a 5-stick solution, but the first and last sticks don't form a 90-degree angle. All I did was add 2 more sticks, and that's it!
I can't (yet) prove how we need at least 7 sticks and not 5. Maybe you can prove/disprove it 🙂
Edit: Seems like @Herbert Kociemba has proven it!
Edit 2: @Jaap Scherphuis did it manually.