Would I be found guilty if I could prove that I didn’t explicitly copy that code but rather just happened to write the same code by arriving at the same solution as the original one I had seen years before?
Nobody can answer this because it depends on the code and the resources of the entity suing you, but in general yes. This is why clean room design is a well-defined strategy: depending on the code and company, you would indeed not be allowed to work on the project because of the fact you'd seen a competitors solution previously.