In KFX format page numbers are part of the e-book file and produced during conversion. For other Kindle formats (MOBI/AZW3) page numbers are in a separate APNX file that is generated by calibre when you send the book to the Kindle device using calibre's device interface.
If you see page numbers sometimes, but not always, something may be going wrong with the APNX generation and transfer process. See
this thread for an example of diagnosing such a problem.