If the shopkeeper says that the yarmulke has been there long enough for the owner to realise that he has lost it (an hour or two?), we can assume that the owner, having realised that it is missing and knowing that most of the people in the city are gentiles who are unlikely to attempt to return the yarmulke to its owner, will have given up hope of seeing it again. In such circumstances, one need not attempt to return it ( - in fact, one may even keep it for oneself) and one may leave it in the store. Furthermore, in this case by leaving it there it will probably have more of a chance of being returned to its owner, who may well retrace his steps and return to retrieve it.
If one has already taken it before the owner might have realised that it is missing, and it has identifying signs on it that the owner might use to establish that it is his, one should attempt to return it to its rightful owner using whatever advertising means are appropriate for the circumstances. One need not spend any money on such efforts that will not be worthwhile for the owner to repay you when he comes to retrieve it.