How a random and deadly stabbing on a bus began with a search for methamphetamine has been revealed in court documents.