We may edit the configure file "/etc/systemd/logind.conf" and change one line from

#HandleLidSwitch=suspend

to

HandleLidSwitch=ignore

And then restart the service.

Restart the systemd daemon with this command:

sudo restart systemd-logind

or, from 15.04 onwards:

sudo service systemd-logind restart

We can also use command:

sudo service systemd-logind status

To check current status.

See: How can I tell Ubuntu to do nothing when I close my laptop lid? - Ask Ubuntu