Exhibit 5.1
    
    
    
    
    
    Karen E. Deschaine
    +1 858 550 6088
    kdeschaine@cooley.com
    
    
    June 3, 2022
    
    
    Castle Biosciences, Inc.
    505 S. Friendswood Drive, Suite 401
    Friendswood, TX 77546
    
    
    Ladies and Gentlemen:
    
    
    We have acted as counsel to Castle Biosciences, Inc., a Delaware corporation (the “Company”), in connection with the filing of a Registration Statement on
      Form S‑3 (the “Registration Statement”) by the Company under the Securities Act of 1933, as amended, covering the resale by certain selling stockholders (the “Selling Stockholders”) of 1,282,045 shares (the “Shares”) of the Company’s Common Stock, par value $0.001 per share (the “Common Stock”), issuable to the Selling Stockholders pursuant to the Agreement and Plan of Merger, dated as of April 4, 2022, by and among the Company, Acorn Merger Sub, Inc., AltheaDx, Inc. and Fortis Advisors LLC (the
      “Merger Agreement”).
    
    
    In connection with this opinion, we have examined and relied upon the Registration Statement and related prospectus, the Company’s Amended and Restated Certificate of Incorporation and Amended and Restated Bylaws, each
      as currently in effect, the Merger Agreement and such other documents, records, certificates, memoranda and other instruments as in our judgment are necessary or appropriate to enable us to render the opinion expressed below. We have assumed the
      genuineness of all signatures, the authenticity of all documents submitted to us as originals, the conformity to originals of all documents submitted to us as copies, the accuracy, completeness and authenticity of certificates of public officials and
      the due authorization, execution and delivery of all documents by all persons other than the Company where execution and delivery are prerequisites to the effectiveness thereof. As to certain factual matters, we have relied upon a certificate of an
      officer of the Company and have not independently verified such matters.
    
    
    We express no opinion to the extent that future issuances of securities of the Company and/or antidilution adjustments to outstanding securities of the Company cause the Shares to be greater than the number of shares
      of Common Stock that then remain authorized but unissued and not committed to be issued by the Company.
    
    
    Our opinion is expressed only with respect to the General Corporation Law of the State of Delaware. We express no opinion as to whether any particular laws other than those identified above are applicable to the
      subject matter hereof.
    
    
    We are not rendering any opinion as to compliance with any federal or state antifraud law, rule or regulation relating to securities, or to the sale or issuance thereof.
    
    
    On the basis of the foregoing, in reliance thereon, and subject to the foregoing, we are of the opinion that the Shares, when issued in accordance with the terms of the Merger Agreement, will be validly issued, fully
      paid and nonassessable.
    
    
    
    
    
    
    Cooley LLP 4401 Eastgate Mall San Diego, CA 92121-1909
    t: (858) 550-6000 f: (858) 550-6420 cooley.com
    
    
    Castle Biosciences, Inc.
    June 3, 2022
    Page Two
    
    
    We hereby consent to the reference to our firm under the caption “Legal Matters” in the prospectus included in the Registration Statement and to the filing of this opinion as an exhibit to the Registration Statement.
    
    
    *****
    
    
    Very truly yours,
    
    
    Cooley LLP
    
    
    
        
          | 
             By: 
           | 
          
             /s/ Karen E. Deschaine 
           | 
            | 
        
        
          |   | 
          
             Karen E. Deschaine, Partner 
           | 
            | 
        
    
    
    
    
    
    
      Cooley LLP 4401 Eastgate Mall San Diego, CA 92121-1909
      t: (858) 550-6000 f: (858) 550-6420 cooley.com