diff --git a/src/PIL/Image.py b/src/PIL/Image.py
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -2479,6 +2479,8 @@ def getdata(self):
             raise ValueError("missing method data")
 
         im = new(self.mode, size, fillcolor)
+        if self.mode == "P" and self.palette:
+            im.palette = self.palette.copy()
         im.info = self.info.copy()
         if method == MESH:
             # list of quads

diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py
--- a/Tests/test_image_transform.py
+++ b/Tests/test_image_transform.py
@@ -32,6 +32,11 @@ def test_info(self):
             new_im = im.transform((100, 100), transform)
         assert new_im.info["comment"] == comment
 
+    def test_palette(self):
+        with Image.open("Tests/images/hopper.gif") as im:
+            transformed = im.transform(im.size, Image.AFFINE, [1, 0, 0, 0, 1, 0])
+            assert im.palette.palette == transformed.palette.palette
+
     def test_extent(self):
         im = hopper("RGB")
         (w, h) = im.size

Problem rotating P images
```python
from PIL import Image
import random

img = Image.open('test.png')
rate = random.randint(30, 330)
img = img.rotate(rate)
img.show()
img.save('test_rotate.png')
```
![test](https://user-images.githubusercontent.com/37957822/127455530-f7437db9-b2df-4b89-be5b-5582b67b4eb8.png)
![test_rotate](https://user-images.githubusercontent.com/37957822/127455537-05a6a378-4ba9-4018-a22f-5f2dabbe6eea.png)

The image generated by rotating the picture is a binary image
If you're looking for an immediate solution, you can convert it to RGB after opening.

```python
from PIL import Image
import random

img = Image.open('test.png').convert('RGB')
rate = random.randint(30, 330)
img = img.rotate(rate)
img.show()
img.save('test_rotate.png')
```
Thank you for your answer. It's useful
This problem was introduced by #5552