Star Trek delivered a mind-bending episode about identity and reality, secretly inspired by one of history’s most influential thinkers.