Incoming payments are automatically linked to invoices with the reference number. If the payment was carried out with or without an incorrect reference number, it will not be automatically linked to an invoice.
You can mark the invoice as paid manually. In order to do so, the payment you wish to link with the invoice has to be in the income category "uncategorized". If this is the case, you can simply go to your invoice and select "Mark as" and then "Paid".
More information can be found here.