The questions linked in the comment by @Eddie Kal, taken together, should answer your question in depth.
In brief, とき literally means "time", and can be used to mean "time while doing something", or "time when something happens / happened / will happen".
In your sample sentence, we can break things down as follows:
- 気【き】づいたときにはたまっているもの
[気づいた]{noticed}[とき]{time when }[に]{at}[は]{ CONTRASTIVE }[たまっている]{ it is accumulating / accumulated }[もの]{ REASON}
(literal) At the time you've noticed it, it will have been accumulated, is the reason
(idiomatic) Because before you know it, it'll be saved up