Over the counter pregnancy tests all work by detecting hormones through urine. You determine whether or not you conceived by peeing on the test itself, or by peeing into a cup and then inserting the test into the cup. Most pregnancy tests are sensitive only to human Chorionic gonadotropin, a hormone that is also known as hCG. A select few can also detect hyperglycosylated hCG. which is produced by the body a bit earlier, sometimes even after an egg is fertilized but before it implanted itself into the lining of the uterus. Both these hormones will be present in higher quantities as pregnancy continues, so the later you test, the more likely you are to get a more accurate test result. If you have heard that you have to test in the morning to be able to trust the result as shown by the test you used, there is some truth in that claim.
Urine generally contains higher quantities of hCG first thing in the morning. This has little to do with the actual time of the day, and more with the fact that your urine is more concentrated and has remained in your bladder for quite some time, because you were asleep all night. That does not mean that early morning urine is the only urine that can give you accurate results though. DIY pregnancy tests are improving in quality all the time, and the modern ones are so sensitive that they can pick up even small amounts of hCG. If you are not doing a pregnancy test early in the morning probably because it just occurred to you that your period is late, or that you are having some symptoms, and you need to know if you are pregnant NOW!
The one thing that you should never do is drink large amounts of fluid, just to be able to pee. Drinking more fluids than you normally would, in a shorter amount of time, dilutes your pee and the hormones detected in it. In short, you can take a pregnancy test at any time of the day and night, but you get the best results if your urine has had some time to "stew". Early morning pee is still considered the best, but well... a girl has got to do what a girl has got to do, right?