The error notice can be caused by many factors.
However if you see that error notice when uploading OR activating a theme/plugin from WP Admin Dashboard, then the main factor are mainly these two things:
1.) The theme/plugin file size is too big
2.) Your website has reached the PHP memory limit of your hosting
If you see the notice when uploading a theme/plugin, it means #1 happens.
If you see the notice when activating a theme/plugin, then #2 happens.
If #1 happens:
It means you can't upload the theme/plugin from your WP Admin dashboard. Instead you have to upload it manually from FTP or from your cPanel. Here's the instructions on how to do it:
If #2 happens:
We recommend to contact your hosting support to temporary increase your PHP memory limit. However if you are comfortable to do it yourself, here are the steps to do it: https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP