"Again, we may put all this together to conclude that our program outputs a boolean value if supplied with an integer input. However, it is important to realise that the presence of $p$ is absolutely essential for the inference to happen. For example, our program might well satisfy $p → q$, but if it doesn’t satisfy $p$ – e.g. if its input is a surname – then we will not be able to derive $q$."
This is text from the book Logic in Computer Science by M. Huth and M. Ryan (page 9).
The second line in the paragraph necessiates the need for p being true, however, the truth table of Implication mentions one case where p is false, but q is true, and the resultant implication is true. How could that be when p is false?
In order to conclude that $q$ is True, we need both that the conditional $p \to q$ holds, i.e. it is True, and that the antecedent $p$ of the conditional is True.
As you says, the truth table for $p \to q$ - in lines where $p$ is False - has True both for $q$ True and for $q$ False.
Thus, from the simple fact that $p \to q$ is True, whe cannot conclude that necessarily $q$ will be True.