In Matthew 17 Jesus, knew Peter's question before he had asked Jesus about it. It was about taxes! Peter had been apprehended by the tax collectors earlier that day. Jesus knew Peter's apprehension by the tax men was not by accident. He knew the stress provoking question to Peter was in fact a precursor to the revelation of Peter's spiritual status.
This is what had happened earlier in Matt 17:24-27