How do you know if an insignificant P value is because of chance error or because the sample size of the data is too small? I have always thought that an insignificant P value is the product of chance causing variation in the data. However when I was watching a talk on a study, the presenter mentioned how the insignificant P value meant that the sample size of the data was too small to make any conclusions rather the being the product of chance error. How can you tell if an insignificant P value is caused chance error or small sample size then?

You do a post hoc / a posteriori power analysis. It answers the question: how likely was I going to find an effect given the size of my sample and the observed effect size (roughly speaking). There is a WIDE range of methods to calculate this given your statistical methods. If you find that you had very little chance of finding an effect with your sample size given the data, your sample size may have been too small.
There are plenty of resources on this:
Differences and relation between retrospective power analysis and a posteriori power analysis?
Also look at G* Power, it’s a piece of software often used for this.
