Audio Memos stops recording when I close the cover of my iPad or close the lid of my Mac

When a Smart Cover (or other MFi compatible cover) attached to an iPad is closed, the internal microphone is disconnected. The same thing happens when the lid of a Macbook is closed. This is a security feature implemented by Apple. See this web page on Apple's server for details. This is not something we can change. You can turn off the screen (by pressing the power button on your iPad) and recording will continue, but you cannot close the cover or the lid.