OS X enforces system sleep and turns off WiFi when the lid of your Mac laptop is closed *UNLESS* very specific requirements are met.
While this behavior can be overridden, OS X must be modified with a kernel extension to do so. Apps from the Mac App Store, such as Amphetamine, are not able to modify OS X using a kernel extension.
1) Use an alternative application: https://code.google.com/p/macosx-nosleep-extension/
2) Meet Apple's requirements for using clamshell mode: https://support.apple.com/en-us/HT201834